KoviAnusha commented on code in PR #57466:
URL: https://github.com/apache/airflow/pull/57466#discussion_r2476274016


##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -66,6 +66,8 @@
 if TYPE_CHECKING:
     from sqlalchemy.orm.attributes import InstrumentedAttribute
     from sqlalchemy.sql import ColumnElement, Select
+else:
+    from sqlalchemy.orm.attributes import InstrumentedAttribute

Review Comment:
   InstrumentedAttribute is needed because in SQLAlchemy 2.0 the typing rules 
got stricter. We have to clearly differentiate normal SQL expressions (like 
ColumnElement) from ORM model attributes. ORM attributes 
(InstrumentedAttribute) come with extra ORM-related stuff like relationship 
tracking and helper methods that regular columns don’t have.
   



##########
airflow-core/src/airflow/api_fastapi/core_api/services/public/dag_run.py:
##########
@@ -57,7 +57,7 @@ def _serialize_xcoms(self) -> dict[str, Any]:
             task_ids=self.result_task_ids,
             dag_ids=self.dag_id,
         )
-        xcom_query = 
self.session.scalars(xcom_query.order_by(XComModel.task_id, 
XComModel.map_index)).all()
+        xcom_results = 
self.session.scalars(xcom_query.order_by(XComModel.task_id, 
XComModel.map_index)).all()

Review Comment:
   @uranusjr, may I know why you want to remove .all()? 
   
   My thought process is we cannot remove .all() because itertools.groupby() on 
line 70 requires a concrete sequence, not a lazy iterator. Without .all(), 
session.scalars() returns a ScalarResult (lazy iterator). itertools.groupby() 
needs to iterate through the data multiple times. The lazy iterator might not 
preserve the sorted order between iterations
   
   With .all(), we get a materialized Sequence[XComModel]. itertools.groupby() 
can reliably group the sorted data. The .all() is functionally necessary, not 
just for type checking.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to