You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "amoghrajesh (via GitHub)" <gi...@apache.org> on 2025/06/09 15:03:21 UTC

[PR] Displaying non native XComs in a human friendly way on UI and API [airflow]

amoghrajesh opened a new pull request, #51535:
URL: https://github.com/apache/airflow/pull/51535

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   Before:
   
   ![image](https://github.com/user-attachments/assets/193eebb7-67db-4704-b6da-96e6d8e05f8e)
   
   
   After:
   
   * After updating UI code
   
   
   TODO:
   
   - [ ] Update PR desc
   - [ ] Add testing details
   - [ ] Fix tests
   - [ ] Update UI code and tests to send "deserialize" flag as true
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Displaying non native XComs in a human readable way on UI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #51535:
URL: https://github.com/apache/airflow/pull/51535#discussion_r2137518043


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/xcom.py:
##########
@@ -69,41 +68,41 @@ def get_xcom_entry(
     stringify: Annotated[bool, Query()] = False,
 ) -> XComResponseNative | XComResponseString:
     """Get an XCom entry."""
-    if deserialize:
-        if not conf.getboolean("api", "enable_xcom_deserialize_support", fallback=False):

Review Comment:
   Next step would be to wipe off this configuration



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Displaying non native XComs in a human readable way on UI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh merged PR #51535:
URL: https://github.com/apache/airflow/pull/51535


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Displaying non native XComs in a human readable way on UI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #51535:
URL: https://github.com/apache/airflow/pull/51535#discussion_r2139489249


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/xcom.py:
##########
@@ -69,41 +68,41 @@ def get_xcom_entry(
     stringify: Annotated[bool, Query()] = False,
 ) -> XComResponseNative | XComResponseString:
     """Get an XCom entry."""
-    if deserialize:
-        if not conf.getboolean("api", "enable_xcom_deserialize_support", fallback=False):

Review Comment:
   This PR is targeted for 3.1, so wiping out can be done at the same milestone level



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Displaying non native XComs in a human readable way on UI [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #51535:
URL: https://github.com/apache/airflow/pull/51535#discussion_r2139530422


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/xcom.py:
##########
@@ -69,41 +68,41 @@ def get_xcom_entry(
     stringify: Annotated[bool, Query()] = False,
 ) -> XComResponseNative | XComResponseString:
     """Get an XCom entry."""
-    if deserialize:
-        if not conf.getboolean("api", "enable_xcom_deserialize_support", fallback=False):
-            raise HTTPException(
-                status.HTTP_400_BAD_REQUEST, "XCom deserialization is disabled in configuration."
-            )
-        query = select(XComModel, XComModel.value)
-    else:
-        query = select(XComModel)
-
-    query = query.where(
-        XComModel.dag_id == dag_id,
-        XComModel.task_id == task_id,
-        XComModel.key == xcom_key,
-        XComModel.map_index == map_index,
+    xcom_query = XComModel.get_many(
+        run_id=dag_run_id,
+        key=xcom_key,
+        task_ids=task_id,
+        dag_ids=dag_id,
+        map_indexes=map_index,
+        session=session,
+        limit=1,
     )
-    query = query.join(DR, and_(XComModel.dag_id == DR.dag_id, XComModel.run_id == DR.run_id))
-    query = query.where(DR.run_id == dag_run_id)
-    query = query.options(joinedload(XComModel.dag_run).joinedload(DR.dag_model))
 
-    if deserialize:
-        item = session.execute(query).one_or_none()
-    else:
-        item = session.scalars(query).one_or_none()
+    # We use `BaseXCom.get_many` to fetch XComs directly from the database, bypassing the XCom Backend.
+    # This avoids deserialization via the backend (e.g., from a remote storage like S3) and instead
+    # retrieves the raw serialized value from the database.
+    result = xcom_query.limit(1).first()
 
-    if item is None:
+    if result is None:
         raise HTTPException(status.HTTP_404_NOT_FOUND, f"XCom entry with key: `{xcom_key}` not found")
 
+    item = copy.copy(result)

Review Comment:
   Ah now I notice there’s an assignment below.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Displaying non native XComs in a human readable way on UI [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #51535:
URL: https://github.com/apache/airflow/pull/51535#discussion_r2139452337


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/xcom.py:
##########
@@ -69,41 +68,41 @@ def get_xcom_entry(
     stringify: Annotated[bool, Query()] = False,
 ) -> XComResponseNative | XComResponseString:
     """Get an XCom entry."""
-    if deserialize:
-        if not conf.getboolean("api", "enable_xcom_deserialize_support", fallback=False):

Review Comment:
   Should this wiping out part also in 3.0.3?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Displaying non native XComs in a human readable way on UI [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #51535:
URL: https://github.com/apache/airflow/pull/51535#discussion_r2139453514


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/xcom.py:
##########
@@ -69,41 +68,41 @@ def get_xcom_entry(
     stringify: Annotated[bool, Query()] = False,
 ) -> XComResponseNative | XComResponseString:
     """Get an XCom entry."""
-    if deserialize:
-        if not conf.getboolean("api", "enable_xcom_deserialize_support", fallback=False):
-            raise HTTPException(
-                status.HTTP_400_BAD_REQUEST, "XCom deserialization is disabled in configuration."
-            )
-        query = select(XComModel, XComModel.value)
-    else:
-        query = select(XComModel)
-
-    query = query.where(
-        XComModel.dag_id == dag_id,
-        XComModel.task_id == task_id,
-        XComModel.key == xcom_key,
-        XComModel.map_index == map_index,
+    xcom_query = XComModel.get_many(
+        run_id=dag_run_id,
+        key=xcom_key,
+        task_ids=task_id,
+        dag_ids=dag_id,
+        map_indexes=map_index,
+        session=session,
+        limit=1,
     )
-    query = query.join(DR, and_(XComModel.dag_id == DR.dag_id, XComModel.run_id == DR.run_id))
-    query = query.where(DR.run_id == dag_run_id)
-    query = query.options(joinedload(XComModel.dag_run).joinedload(DR.dag_model))
 
-    if deserialize:
-        item = session.execute(query).one_or_none()
-    else:
-        item = session.scalars(query).one_or_none()
+    # We use `BaseXCom.get_many` to fetch XComs directly from the database, bypassing the XCom Backend.
+    # This avoids deserialization via the backend (e.g., from a remote storage like S3) and instead
+    # retrieves the raw serialized value from the database.
+    result = xcom_query.limit(1).first()
 
-    if item is None:
+    if result is None:
         raise HTTPException(status.HTTP_404_NOT_FOUND, f"XCom entry with key: `{xcom_key}` not found")
 
+    item = copy.copy(result)

Review Comment:
   Why is this needed?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Displaying non native XComs in a human readable way on UI [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #51535:
URL: https://github.com/apache/airflow/pull/51535#discussion_r2139487753


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/xcom.py:
##########
@@ -69,41 +68,41 @@ def get_xcom_entry(
     stringify: Annotated[bool, Query()] = False,
 ) -> XComResponseNative | XComResponseString:
     """Get an XCom entry."""
-    if deserialize:
-        if not conf.getboolean("api", "enable_xcom_deserialize_support", fallback=False):
-            raise HTTPException(
-                status.HTTP_400_BAD_REQUEST, "XCom deserialization is disabled in configuration."
-            )
-        query = select(XComModel, XComModel.value)
-    else:
-        query = select(XComModel)
-
-    query = query.where(
-        XComModel.dag_id == dag_id,
-        XComModel.task_id == task_id,
-        XComModel.key == xcom_key,
-        XComModel.map_index == map_index,
+    xcom_query = XComModel.get_many(
+        run_id=dag_run_id,
+        key=xcom_key,
+        task_ids=task_id,
+        dag_ids=dag_id,
+        map_indexes=map_index,
+        session=session,
+        limit=1,
     )
-    query = query.join(DR, and_(XComModel.dag_id == DR.dag_id, XComModel.run_id == DR.run_id))
-    query = query.where(DR.run_id == dag_run_id)
-    query = query.options(joinedload(XComModel.dag_run).joinedload(DR.dag_model))
 
-    if deserialize:
-        item = session.execute(query).one_or_none()
-    else:
-        item = session.scalars(query).one_or_none()
+    # We use `BaseXCom.get_many` to fetch XComs directly from the database, bypassing the XCom Backend.
+    # This avoids deserialization via the backend (e.g., from a remote storage like S3) and instead
+    # retrieves the raw serialized value from the database.
+    result = xcom_query.limit(1).first()
 
-    if item is None:
+    if result is None:
         raise HTTPException(status.HTTP_404_NOT_FOUND, f"XCom entry with key: `{xcom_key}` not found")
 
+    item = copy.copy(result)

Review Comment:
   I think its mainly so that we do not modify the session bound object: `result`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Displaying non native XComs in a human readable way on UI [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #51535:
URL: https://github.com/apache/airflow/pull/51535#discussion_r2139455038


##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_xcom.py:
##########
@@ -72,6 +72,8 @@ def _create_xcom(key, value, backend, session=None) -> None:
         session=session,
     )
 
+    print("hi")
+

Review Comment:
   ```suggestion
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org