Skip to content

Fixes #36328: skip custom recognizers Presidio cannot compile - #36329

Merged
stout-yeoman merged 4 commits into
open-metadata:mainfrom
vamsibvv:fix/recognizer-invalid-regex
Nov 12, 2026
Merged

stout-yeoman merged 4 commits into
open-metadata:mainfrom
vamsibvv:fix/recognizer-invalid-regex

Conversation

@vamsibvv

@vamsibvv vamsibvv commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #36328

A pattern recognizer with an invalid regex or with no patterns raised during analysis (Presidio compiles patterns on first use, and rejects an empty pattern list), so the whole column failed and lost every other tag scored for it. The same happened to a context recognizer whose context word contains regex characters, because the words went into the regex unescaped.

  • _create_pattern_recognizer compiles the patterns with regex (what Presidio uses) and the recognizer's flags while building it. If that or Presidio's constructor fails, it logs an error and returns None, so only that recognizer is skipped. Built-in recognizers are untouched.
  • Context words are escaped, so c++ and id (internal) match literally and a.k.a no longer matches aXkXa.
  • minScore: 0 is no longer treated as unset (it scored 0.6 even with maxScore: 0.4).

Type of change:

  • Bug fix

High-level design:

N/A — small change.

Tests:

Use cases covered

  • A tag with a broken pattern recognizer (invalid regex, or patterns: []) no longer stops another tag on the same column from being applied.
  • Context words with regex characters match as plain text.
  • A context recognizer with minScore: 0 scores the midpoint.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated: tests/unit/pii/algorithms/test_presidio_recognizer_factory.py, tests/unit/metadata/pii/test_tag_scoring.py
  • The 8 new tests fail on main and pass with this change. All 937 tests in tests/unit/pii and tests/unit/metadata/pii pass.
  • Coverage %: 95% on presidio_recognizer_factory.py (the uncovered lines are existing branches this PR does not touch)

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Not run: no connector changes.

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  1. Scored an email column with ScoreTagsForColumnService for PII.Sensitive plus a custom tag whose recognizer is broken (invalid regex, empty patterns, or a context word id (internal).
  2. On main each case raises, so the column gets no tags. With this change PII.Sensitive is returned, and the broken recognizer is logged and skipped.

UI screen recording:

Not applicable — ingestion-only bug fix.

Checklist:

  • I have read the CONTRIBUTING document.

  • My PR title is Fixes <issue-number>: <short explanation>

  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.

  • I have commented on my code, particularly in hard-to-understand areas.

  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.

  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable).

  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.

  • Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under docs/decisions/ (see its README.md). This description is gone from git log after the squash-merge.

  • I have added a test that covers the exact scenario we are fixing.

AI assistance (Claude Code) was used for this change.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

The PR skips custom pattern recognizers that Presidio cannot compile, without dropping other tags.

  • Column scoring skips pattern recognizers Presidio cannot build.
  • Context words with punctuation match as written.
  • Context recognizers include a zero minimum in their midpoint score.

Reviews (1) · Last reviewed commit: "Fixes #36328: skip custom recognizers Pr..." · Reviewed by Greptile

…mpile

A pattern recognizer with an invalid regex or no patterns raised during
analysis and failed the whole column, dropping every other tag on it.
Compile the patterns when the recognizer is built and skip it with an
error log instead. Escape context words so they match literally, and
keep a minScore of 0.
@vamsibvv
vamsibvv requested a review from a team as a code owner October 27, 2026 08:34
@vamsibvv
vamsibvv requested a review from mohittilala October 27, 2026 08:34
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@vamsibvv

Copy link
Copy Markdown
Contributor Author

@TeddyCr @Khairajani could one of you add the safe to test label and put #36328 in the Shipping project? CI and the PR metadata check are blocked on those. The fix stops one custom recognizer with a bad regex from dropping every PII tag on the column.

@stout-yeoman
stout-yeoman self-requested a review October 30, 2026 09:04
regex raises RecursionError, not regex.error, for a pattern such as
'(' * 350 + 'a' + ')' * 350, so the pre-compilation check let it escape
and fail the column, even for a recognizer in another language.
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@harshach harshach added the safe to test Add this label to run secure Github workflows on PRs label Oct 31, 2026
@github-actions github-actions Bot removed the safe to test Add this label to run secure Github workflows on PRs label Oct 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@stout-yeoman stout-yeoman added the safe to test Add this label to run secure Github workflows on PRs label Nov 3, 2026
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@stout-yeoman
stout-yeoman removed the request for review from mohittilala November 3, 2026 16:01
auto-merge was automatically disabled November 11, 2026 06:51

Head branch was pushed to by a user without write access

@vamsibvv
vamsibvv force-pushed the fix/recognizer-invalid-regex branch from 5ba4b9a to b4cfd83 Compare November 11, 2026 06:51
@stout-yeoman
stout-yeoman enabled auto-merge (squash) November 12, 2026 10:24
@gitar-bot

gitar-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

Changing PII recognizer compilation, literal context matching, and zero-score handling could alter detected tags and produce false positives or negatives.

Skips custom pattern recognizers that Presidio cannot compile instead of failing the whole column, escapes context words so regex characters match literally, and fixes minScore: 0 being treated as unset. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@stout-yeoman
stout-yeoman merged commit 0935836 into open-metadata:main Nov 12, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-classification: one custom recognizer with an invalid regex drops every tag on the column

4 participants