uranusjr commented on code in PR #27834:
URL: https://github.com/apache/airflow/pull/27834#discussion_r1031924565


##########
airflow/models/abstractoperator.py:
##########
@@ -494,18 +495,30 @@ def expand_mapped_task(self, run_id: str, *, session: 
Session) -> tuple[Sequence
                     total_length,
                 )
                 unmapped_ti.state = TaskInstanceState.SKIPPED
-                indexes_to_map = ()
             else:
-                # Otherwise convert this into the first mapped index, and 
create
-                # TaskInstance for other indexes.
-                unmapped_ti.map_index = 0
-                self.log.debug("Updated in place to become %s", unmapped_ti)
-                all_expanded_tis.append(unmapped_ti)
-                indexes_to_map = range(1, total_length)
-            state = unmapped_ti.state
-        elif not total_length:
+                zero_index_ti_exists = session.query(
+                    exists().where(
+                        TaskInstance.dag_id == self.dag_id,
+                        TaskInstance.task_id == self.task_id,
+                        TaskInstance.run_id == run_id,
+                        TaskInstance.map_index == 0,
+                    )
+                ).scalar()

Review Comment:
   IIRC `EXISTS` has some compatibility issues across databases (don’t remember 
what exactly), so we generally use `query(count())...scalar() > 0` instead.



-- 
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