kaxil commented on code in PR #67902:
URL: https://github.com/apache/airflow/pull/67902#discussion_r3344829638


##########
airflow-core/tests/unit/state/test_metastore.py:
##########
@@ -429,6 +429,45 @@ def test_different_assets_are_isolated(
 
         assert backend.get(scope2, "watermark", session=session) is None
 
+    def test_set_asset_store_writes_ti_id(
+        self, backend: MetastoreStoreBackend, asset_committed: AssetModel, 
create_task_instance
+    ):
+        ti = create_task_instance()
+        scope = AssetScope(asset_id=asset_committed.id)
+        backend.set_asset_store(scope, "watermark", "v", ti_id=ti.id)
+
+        with create_session() as s:
+            row = 
s.scalar(select(AssetStoreModel).where(AssetStoreModel.asset_id == 
asset_committed.id))
+        assert row is not None
+        assert row.last_updated_by_ti_id == ti.id
+
+    @pytest.mark.backend("postgres", "mysql", "sqlite")
+    def test_set_asset_store_upsert_updates_ti_id(
+        self, backend: MetastoreStoreBackend, asset_committed: AssetModel, 
create_task_instance
+    ):
+        ti1 = create_task_instance(task_id="task1")
+        ti2 = create_task_instance(task_id="task2")

Review Comment:
   This test fails on every backend in CI (it's why the run is red), not flaky:
   
   ```
   sqlalchemy.exc.IntegrityError: UNIQUE constraint failed: dag_run.dag_id, 
dag_run.run_id
   ```
   
   `create_task_instance` defaults to `dag_id="dag"` with a default `run_id` 
and creates a fresh dag_run each call, so these two calls collide on the 
dag_run unique key. Only `task_id` differs, which doesn't help since the 
collision is on the dag_run, not the TI. Distinct dag runs fix it:
   
   ```python
   ti1 = create_task_instance(task_id="task1", dag_id="dag1")
   ti2 = create_task_instance(task_id="task2", dag_id="dag2")
   ```
   
   (distinct `run_id` works too). The test only needs two distinct TI ids, so 
separate dag runs satisfy the intent.
   



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