Lee-W commented on code in PR #46460:
URL: https://github.com/apache/airflow/pull/46460#discussion_r1952066231


##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -1325,18 +1329,21 @@ def _create_dag_runs_asset_triggered(
         session: Session,
     ) -> None:
         """For DAGs that are triggered by assets, create dag runs."""
-        # Bulk Fetch DagRuns with dag_id and logical_date same
+        # Bulk Fetch DagRuns with dag_id and run_after same
         # as DagModel.dag_id and DagModel.next_dagrun
         # This list is used to verify if the DagRun already exist so that we 
don't attempt to create
         # duplicate dag runs
-        logical_dates = {
-            dag_id: timezone.coerce_datetime(last_time)
-            for dag_id, (_, last_time) in asset_triggered_dag_info.items()
+        triggered_dates: dict[str, DateTime] = {
+            dag_id: timezone.coerce_datetime(last_asset_event_time)
+            for dag_id, (_, last_asset_event_time) in 
asset_triggered_dag_info.items()
         }
         existing_dagruns: set[tuple[str, timezone.DateTime]] = set(
             session.execute(
-                select(DagRun.dag_id, DagRun.logical_date).where(
-                    tuple_(DagRun.dag_id, 
DagRun.logical_date).in_(logical_dates.items())
+                select(DagRun.dag_id, DagRun.run_after).where(
+                    and_(
+                        DagRun.triggered_by == DagRunTriggeredByType.ASSET,
+                        tuple_(DagRun.dag_id, 
DagRun.run_after).in_(triggered_dates.items()),
+                    )
                 )
             )
         )

Review Comment:
   I thought this was to prevent an edge case in duplicate DagRun from being 
created (previously, it would raise a db error). Even if we don't encounter 
runs with the same logical date, we probably don't want to create duplicate 
DagRun either.



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