test(airflow): isolate yield_pipeline_status tests from SQLAlchemy registry pollution#28995
Conversation
…gistry pollution TestYieldPipelineStatus built its fake DagRun with MagicMock(spec=DagRun). Building a spec'd mock makes unittest.mock walk dir(DagRun); DagRun's association proxies resolve through orm.class_mapper(), which forces SQLAlchemy to configure the entire shared mapper registry (cascade=True). If any other test on the same xdist worker has left a mapper in a failed state (e.g. airflow's DagWarning mapper failing to initialize), that cascade re-raises InvalidRequestError and these two date-fallback tests fail for reasons unrelated to what they verify. Because xdist work distribution shifts with the test corpus, the failure surfaces on some PRs and not others, which reads as flakiness. Use a SimpleNamespace carrying exactly the attributes yield_pipeline_status reads. It never introspects DagRun, so it cannot trigger mapper configuration, and it still raises AttributeError on unexpected access.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
|
🟡 Playwright Results — all passed (13 flaky)✅ 4291 passed · ❌ 0 failed · 🟡 13 flaky · ⏭️ 88 skipped
🟡 13 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
Code Review ✅ ApprovedReplaces MagicMock with SimpleNamespace in yield_pipeline_status tests to prevent SQLAlchemy mapper registry pollution. This change eliminates intermittent CI failures caused by cross-test dependency on registry configuration. OptionsDisplay: compact → Showing less information. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |



Problem
tests/unit/airflow/test_airflow_metadata.py::TestYieldPipelineStatus::{test_uses_start_date_when_logical_date_is_none, test_skips_run_when_both_dates_are_none}intermittently fail in CI (e.g. on #28977) with:Root cause
Building
MagicMock(spec=DagRun)makesunittest.mockwalkdir(DagRun).DagRun's association proxies resolve throughorm.class_mapper(), which calls_check_configure()→_configure_registries({registry}, cascade=True)— i.e. configuring the entire shared SQLAlchemy mapper registry just to build the mock.If any other test scheduled on the same
pytest -n autoworker has already left a mapper in a failed state (here airflow'sDagWarningmapper, marked_configure_failed), that cascade re-raises and these two tests fail — even though the failure has nothing to do with the date-fallback logic they verify.Because xdist work distribution shifts with the overall test corpus, the two tests fail on some PRs (#28977) and pass on others (#28991) despite identical base — which reads as flakiness. The tests pass in isolation and when their file is run alone.
Fix
Build the fake
DagRunwithtypes.SimpleNamespacecarrying exactly the attributesyield_pipeline_statusreads (run_id,dag_id,state,logical_date,start_date). It never introspectsDagRun, so it cannot trigger mapper configuration, and — being a real object — still raisesAttributeErroron unexpected attribute access, preserving the typo-safetyspec=gave.Test-only change; the 16 tests in the file pass unchanged.