Copilot commented on code in PR #69830:
URL: https://github.com/apache/airflow/pull/69830#discussion_r3603037246


##########
airflow-core/tests/unit/dag_processing/test_manager.py:
##########
@@ -2712,6 +2712,30 @@ def test_get_bundle_state_returns_correct_state(self, 
session):
 
         assert state == BundleState(last_refreshed=refreshed_at, version="v1")
 
+    def test_get_bundle_state_reads_latest_database_values(self, session):
+        bundle_name = "test_fresh_state_bundle"
+        initial_refreshed_at = timezone.datetime(2024, 1, 15, 12, 0, 0)
+        refreshed_at = timezone.datetime(2024, 1, 16, 12, 0, 0)
+        model = DagBundleModel(name=bundle_name, version="old")
+        model.last_refreshed = initial_refreshed_at
+        session.add(model)
+        session.commit()
+
+        manager = DagFileProcessorManager(max_runs=1)
+        state = manager.get_bundle_state(bundle_name, session=session)
+
+        assert state == BundleState(last_refreshed=initial_refreshed_at, 
version="old")
+
+        with create_session() as update_session:
+            update_model = update_session.get(DagBundleModel, bundle_name)
+            assert update_model is not None
+            update_model.last_refreshed = refreshed_at
+            update_model.version = "fresh"
+
+        state = manager.get_bundle_state(bundle_name, session=session)

Review Comment:
   This test uses `create_session()` (scoped session) to simulate a second DB 
session, but `create_session()` defaults to `scoped=True` and will reuse the 
same thread-local `settings.Session` instance. That means the “update_session” 
may actually be the same session (and may even be closed/committed 
unexpectedly), so the test doesn’t reliably validate cross-session freshness. 
Also, on SQLite/MySQL the original session may be holding an open transaction 
snapshot from the first read; committing the original session before the second 
read makes the test deterministic while still keeping the identity map stale 
(`expire_on_commit=False`).



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