This is an automated email from the ASF dual-hosted git repository.

amoghrajesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 509124275f4 Clamp negative offset in mapped XCom slice queries (#75015)
509124275f4 is described below

commit 509124275f42abf554bb7ad194cbf6e18b44e6d1
Author: Sahil Ray <[email protected]>
AuthorDate: Thu Nov 12 13:41:01 2026 +0530

    Clamp negative offset in mapped XCom slice queries (#75015)
    
    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.
---
 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 81c6908cd05..c3ee9788591 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
@@ -392,6 +392,7 @@ def get_mapped_xcom_by_index(
 
 
 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 bf76fa48b90..fd2df490449 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
@@ -1169,6 +1169,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):

Reply via email to