Skip to content

Fix Non-DB test collection failure in Google Stackdriver hook test - #74066

Merged
shahar1 merged 1 commit into
apache:mainfrom
FrankYang0529:airflow-stackdriver-test-mapper-init
Oct 2, 2026
Merged

shahar1 merged 1 commit into
apache:mainfrom
FrankYang0529:airflow-stackdriver-test-mapper-init

Conversation

@FrankYang0529

Copy link
Copy Markdown
Member

The CI in #68625 failed with following message:

ERROR providers/google/tests/unit/google/cloud/hooks/test_stackdriver.py - sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper[AssetWatcherModel(asset_watcher)], expression 'Trigger' failed to locate a name ('Trigger'). If this is a class name, consider adding this relationship() to the <class 'airflow.models.asset.AssetWatcherModel'> class after both dependent classes have been defined.

https://github.com/apache/airflow/actions/runs/36953939813/job/110675454131?pr=68625

Why

  • test_stackdriver.py passes Connection(conn_id="google_cloud_default") as the return_value of a mock.patch decorator. That expression runs when pytest imports the module during collection. Creating the ORM object makes SQLAlchemy configure every mapper that is registered at that moment.
  • No test setup imports all models before collection. For a PR that only changes the kafka provider, selective checks run only the apache.kafka, common.compat, common.messaging and google tests. The kafka asset tests import the airflow.models.asset module through common.compat. That module defines AssetWatcherModel, which has a relationship to Trigger. No test module has imported airflow.models.trigger yet when test_stackdriver.py is collected.

How

  • Change it to mock.MagicMock(spec=Connection).

Was generative AI tooling used to co-author this PR?
  • Yes - Claude Code

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

Signed-off-by: PoAn Yang <payang@apache.org>
@FrankYang0529
FrankYang0529 marked this pull request as ready for review October 2, 2026 05:25
@FrankYang0529
FrankYang0529 requested a review from shahar1 as a code owner October 2, 2026 05:25
@shahar1
shahar1 merged commit 58e987d into apache:main Oct 2, 2026
166 checks passed
@FrankYang0529
FrankYang0529 deleted the airflow-stackdriver-test-mapper-init branch October 2, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants