Fix crossed-bound XCom slices returning wrong rows via negative SQL L…#69273
Open
bramhanandlingala wants to merge 1 commit into
Open
Fix crossed-bound XCom slices returning wrong rows via negative SQL L…#69273bramhanandlingala wants to merge 1 commit into
bramhanandlingala wants to merge 1 commit into
Conversation
bramhanandlingala
requested review from
amoghrajesh,
ashb and
kaxil
as code owners
July 2, 2026 19:18
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the XCom sequence-slice endpoint (
get_mapped_xcom_by_slice) returning incorrect rows — or erroring, depending on the database backend — when a requested slice has crossed bounds (i.e. the effective stop comes before the effective start, which Python evaluates as an empty result).Root cause
The endpoint maps Python slice semantics onto SQLAlchemy's
Query.slice(low, high), which compiles to:When
high <= low, this produces a negativeLIMIT, which SQLAlchemy does not clamp:LIMITas "no limit" and silently returns the wrong (extra) rows instead of an empty result.LIMITcannot be negative.This affects 4 of the branches in
get_mapped_xcom_by_slice— specifically where bothstartandstopare provided and aCOUNTquery is needed to resolve a mixed-sign bound (e.g.start=2, stop=-3), since that's where a crossed slice can occur without either individual bound being invalid on its own.Fix
Added a small helper,
_sliced_or_empty(), that checks for crossed bounds before calling.slice()and returns.limit(0)instead:Replaced the 4 affected
query.slice(...)calls with_sliced_or_empty(query, ...). No other logic changes — non-crossed slices behave exactly as before.Files changed
airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.pyairflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_xcoms.pyTesting
Added tests covering all 4 previously-affected branches, verified against real Python slice semantics.
Fixes #69204
Gen-AI disclosure: I used a generative AI tool to help identify the root
cause, write tests, and draft the PR description. I reviewed, tested, and
verified all changes locally before submitting.
Was generative AI tooling used to co-author this PR?
Generated-by: Claude following the guidelines