Skip to content

[BUGFIX] Reject empty regex_list in ExpectColumnValuesToMatchRegexList#11958

Open
anxkhn wants to merge 2 commits into
fivetran:developfrom
anxkhn:fix/match-regex-list-empty-validator
Open

[BUGFIX] Reject empty regex_list in ExpectColumnValuesToMatchRegexList#11958
anxkhn wants to merge 2 commits into
fivetran:developfrom
anxkhn:fix/match-regex-list-empty-validator

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 7, 2026

Copy link
Copy Markdown

ExpectColumnValuesToMatchRegexList declared its regex_list field with no
non-empty validator, so constructing it with an empty list succeeded:

import great_expectations.expectations as gxe

# Accepted today, no error at construction:
gxe.ExpectColumnValuesToMatchRegexList(column="my_col", regex_list=[])

At validate time the pandas metric builds its match frame with
pd.concat(regex_matches, axis=1, ...). With an empty regex_list the loop
that populates regex_matches never runs, so the call becomes
pd.concat([], axis=1) and raises ValueError: No objects to concatenate. This
surfaces to the user as a MetricResolutionError with the opaque message
"No objects to concatenate", which gives no hint that the real problem is the
empty regex_list.

This is an asymmetry rather than a design choice:

  • The SQLAlchemy branch of the same metric already guards it
    (column_values_match_regex_list.py: raises "At least one regex must be
    supplied in the regex_list.").
  • The mirror expectation ExpectColumnValuesToNotMatchRegexList already has a
    @pydantic.validator("regex_list") that rejects empties with "regex_list must
    not be empty". The like_pattern_list expectations have the same guard.

Only ExpectColumnValuesToMatchRegexList was missing the construction-time
validator, so its empty-list input reached the unguarded pandas pd.concat and
crashed.

Change

  • Add a @pydantic.validator("regex_list") to ExpectColumnValuesToMatchRegexList
    that raises ValueError("regex_list must not be empty") when the list is empty.
    It is identical to the validator already used on the not-match sibling, so the
    two expectations now behave consistently and fail fast at construction with a
    clear message. Non-empty lists are unaffected.
  • Add a @pytest.mark.unit regression test mirroring the not-match sibling's
    test_invalid_config.

How it behaves after the change

import great_expectations.expectations as gxe

gxe.ExpectColumnValuesToMatchRegexList(column="my_col", regex_list=[])
# pydantic.ValidationError: ... regex_list must not be empty

gxe.ExpectColumnValuesToMatchRegexList(column="my_col", regex_list=["^a"])
# still constructs fine - no behavior change for valid input

Checklist (from the template)

  • Description of PR changes above includes a link to an existing GitHub issue

ExpectColumnValuesToMatchRegexList declared regex_list with no non-empty
validator, so constructing it with regex_list=[] succeeded. The pandas
metric then called pd.concat([], axis=1) and raised the opaque
'No objects to concatenate' at validate time.

Add a pydantic validator on regex_list that fails fast at construction
with a clear message, matching the existing validator on the sibling
ExpectColumnValuesToNotMatchRegexList and the metric's own SQLAlchemy
guard. Non-empty lists are unaffected.

Add a unit regression test mirroring the not-match sibling's
test_invalid_config.

Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
@netlify

netlify Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploy Preview for niobium-lead-7998 canceled.

Name Link
🔨 Latest commit 7421b14
🔍 Latest deploy log https://app.netlify.com/projects/niobium-lead-7998/deploys/6a4e4eb24ffe0100081e6f16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants