Skip to content

API: Fix prefix pattern search returning rows without the prefix - #73520

Merged
pierrejeambrun merged 1 commit into
apache:mainfrom
Eason09053360:fix-prefix-pattern-range-overmatch
Sep 22, 2026
Merged

pierrejeambrun merged 1 commit into
apache:mainfrom
Eason09053360:fix-prefix-pattern-range-overmatch

Conversation

@Eason09053360

Copy link
Copy Markdown
Contributor

Why

*_prefix_pattern filters turn a prefix into an index-friendly range scan. When bumping the last character would leave the alphanumeric range (9, z, Z), the upper bound is recomputed from a shorter prefix, so the range is far wider than what was asked for — dag_9 also returns dag_abc, and z gets no upper bound at all. Every *_prefix_pattern parameter is affected.

What

  • airflow-core/src/airflow/api_fastapi/common/parameters/search.py: both _prefix_clause implementations add substr(column, 1, len(prefix)) = prefix beside the bounds — an equality rather than LIKE, so it resolves under the same collation as >=/< (LIKE is case-insensitive on SQLite and on MySQL _ci columns).
  • The bounds are untouched and the documented trailing-punctuation strip (test_ matches test) still holds; a new SQLite-backed test pins both down.
  • The collation premise behind the alnum restriction looks unverified — happy to drop the restriction instead of narrowing if a reviewer knows it does not hold.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5)

Generated-by: Claude Code (Opus 5) following the guidelines

The *_prefix_pattern filters turn a prefix into an index-friendly range
scan. Whenever bumping the last character would leave the alphanumeric
range ('9', 'z', 'Z'), the upper bound is recomputed from a shorter
prefix, so the scanned range is far wider than the prefix the caller
asked for: searching "dag_9" also returns "dag_abc", searching "a9"
returns everything starting with "a", and searching "z" gets no upper
bound at all. This affects every *_prefix_pattern query parameter, so a
UI search box and a REST client both get results that do not match what
was typed.

The documented trade-off of stripping trailing non-alphanumeric
characters is deliberate and stays; only the undocumented widening is
addressed here, and the bounds themselves are left alone so the B-tree
index still drives the scan.

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM

@pierrejeambrun pierrejeambrun added this to the Airflow 3.3.3 milestone Sep 22, 2026
@pierrejeambrun
pierrejeambrun merged commit 6036de1 into apache:main Sep 22, 2026
79 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport failed to create: v3-3-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
❌ v3-3-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 6036de1 v3-3-test

This should apply the commit to the v3-3-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

pierrejeambrun added a commit that referenced this pull request Sep 23, 2026
) (#73558)

The *_prefix_pattern filters turn a prefix into an index-friendly range
scan. Whenever bumping the last character would leave the alphanumeric
range ('9', 'z', 'Z'), the upper bound is recomputed from a shorter
prefix, so the scanned range is far wider than the prefix the caller
asked for: searching "dag_9" also returns "dag_abc", searching "a9"
returns everything starting with "a", and searching "z" gets no upper
bound at all. This affects every *_prefix_pattern query parameter, so a
UI search box and a REST client both get results that do not match what
was typed.

The documented trade-off of stripping trailing non-alphanumeric
characters is deliberate and stays; only the undocumented widening is
addressed here, and the bounds themselves are left alone so the B-tree
index still drives the scan.


(cherry picked from commit 6036de1)

Co-authored-by: Y-C <[email protected]>
Co-authored-by: Eason09053360 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants