This is an automated email from the ASF dual-hosted git repository.
vatsrahul1001 pushed a commit to branch v3-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-4-test by this push:
new 4346b823c0c [v3-4-test] Clamp negative offset in mapped XCom slice
queries (#75015) (#77683)
4346b823c0c is described below
commit 4346b823c0c0041142e71705ddfb230d89ce9285
Author: Rahul Vats <[email protected]>
AuthorDate: Fri Nov 27 19:29:01 2026 +0530
[v3-4-test] Clamp negative offset in mapped XCom slice queries (#75015)
(#77683)
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.
(cherry picked from commit 509124275f42abf554bb7ad194cbf6e18b44e6d1)
Co-authored-by: Sahil Ray <[email protected]>
Co-authored-by: Claude <[email protected]>
---
airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py | 1 +
.../tests/unit/api_fastapi/execution_api/versions/head/test_xcoms.py | 3 +++
2 files changed, 4 insertions(+)
diff --git a/airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py
b/airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py
index a8f326d84be..1f854426489 100644
--- a/airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py
+++ b/airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py
@@ -382,6 +382,7 @@ class GetXComSliceFilterParams(BaseModel):
def _get_sliced_query_or_empty(query: Select, low: int, high: int) -> Select:
+ low = max(low, 0)
if high <= low:
return query.limit(0)
return query.slice(low, high)
diff --git
a/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_xcoms.py
b/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_xcoms.py
index a9bf99e5c05..e7b25e6ff32 100644
---
a/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_xcoms.py
+++
b/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_xcoms.py
@@ -1115,6 +1115,9 @@ class TestXComsGetEndpoint:
pytest.param(slice(-1, None, -1), id="-1::-1"),
pytest.param(slice(-2, -1, None), id="-2:-1"),
pytest.param(slice(-1, -3, -1), id="-1:-3:-1"),
+ pytest.param(slice(-2, 10, None), id="-2:10"),
+ pytest.param(slice(2, -10, -1), id="2:-10:-1"),
+ pytest.param(slice(1, -10, -1), id="1:-10:-1"),
],
)
def test_xcom_get_with_slice(self, client, dag_maker, session, key):