Repository navigation
Fix mapped XCom slices with out-of-range bounds returning wrong rows - #75015
Open
sahilSENPAII wants to merge 1 commit into
Open
sahilSENPAII wants to merge 1 commit into
sahilSENPAII wants to merge 1 commit into
Conversation
Eason09053360
approved these changes
Oct 18, 2026
Eason09053360
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the patch! LGTM.
A slice bound that falls before the first mapped XCom, such as seq[-2:10] or seq[2:-10:-1], maps to a negative low bound once the other end is resolved against the row count. That reached the database as a negative OFFSET: SQLite treats it as zero and returns extra rows instead of what Python slicing gives, while Postgres and MySQL reject the query. Python clamps such a bound to the start of the sequence, so the query must as well.
sahilSENPAII
force-pushed
the
clamp-negative-offset-in-mapped-xcom-slice
branch
from
November 5, 2026 21:08
e79a5a6 to
b6360a1
Compare
Contributor
Author
|
Rebased on latest main and CI is green. @amoghrajesh could you take a look when you have time? Thanks. |
This branch has not been deployed
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.
related: #69204, #72584
Problem
GET /execution/xcoms/{dag_id}/{run_id}/{task_id}/{key}/slicereturns wrong rows, or fails, when one slice bound lies before the first mapped XCom once it is resolved against the row count. With 3 mapped XComs["f", "o", "b"]:seq[-2:10]["o", "b"]LIMIT 9 OFFSET -7["f", "o", "b"]seq[1:-10:-1]["o", "f"]LIMIT 8 OFFSET -6["b", "o", "f"]seq[2:-10:-1]["b", "o", "f"]LIMIT 9 OFFSET -6["b", "o", "f"](correct by chance)Cause
_get_sliced_query_or_emptypasseslowtoSelect.slice()unchanged, and SQLAlchemy compiles a negativelowto a negativeOFFSETwithLIMIT high - low. SQLite treats the negative offset as 0, so the inflated limit returns extra rows. Postgres and MySQL reject the query. A negativelowis possible in two branches ofget_mapped_xcom_by_slice: a non-negativestartwith a negativestepand astopbelow-len, and a negativestartwith a positivestepand astopabovelen. #72584 fixed the crossed-bounds case (high <= low) in the same helper, but not this one.Fix
Clamp
lowto 0 in_get_sliced_query_or_emptybefore the existinghigh <= lowcheck. This matches how Python slicing clamps an out-of-range bound to the start of the sequence. The other two call sites always pass a non-negativelow, so they are unchanged.Testing
-2:10,2:-10:-1and1:-10:-1to the parametrizedtest_xcom_get_with_slice, which compares the response with Python slicing.-2:10and1:-10:-1fail, and2:-10:-1passes because the inflated limit happens to cover every row. Postgres and MySQL reject the negative offset in all three cases, so they would fail there too. I checked this by compiling the query for each dialect, not by running those backends.test_xcoms.pymodule passes on a fresh SQLite database: 156 passed.prek run --stage pre-commitpasses on the changed files.generate-openapi-specandcheck-tests-in-the-right-folderswere skipped because they need Breeze images.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.