michaelmicheal commented on code in PR #29433:
URL: https://github.com/apache/airflow/pull/29433#discussion_r1113218259


##########
airflow/datasets/manager.py:
##########
@@ -55,23 +61,33 @@ def register_dataset_change(
         dataset_model = session.query(DatasetModel).filter(DatasetModel.uri == 
dataset.uri).one_or_none()
         if not dataset_model:
             self.log.warning("DatasetModel %s not found", dataset)
-            return
-        session.add(
-            DatasetEvent(
+            return None
+
+        if task_instance:
+            dataset_event = DatasetEvent(
                 dataset_id=dataset_model.id,
                 source_task_id=task_instance.task_id,
                 source_dag_id=task_instance.dag_id,
                 source_run_id=task_instance.run_id,
                 source_map_index=task_instance.map_index,
                 extra=extra,
             )
-        )
+        else:
+            # When an external dataset change is made through the API, it 
isn't triggered by a task instance,
+            # so we create a DatasetEvent without the task and dag data.
+            dataset_event = DatasetEvent(

Review Comment:
   What do you think of the latest changes?



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