-
Notifications
You must be signed in to change notification settings - Fork 16.9k
Fix SQLAlchemy mapper init failure when DB tests are skipped #65127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wjddn279
wants to merge
1
commit into
apache:main
Choose a base branch
from
wjddn279:fix-non-db-test-sqlalchemy-mapper-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+6
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a workaround, but not really a solution - you suggest to perform costly ORM initialization in non-DB mode. The root problem is that ORM-objects are created during initialization even in non-DB mode right here:
airflow/airflow-core/tests/unit/serialization/test_serialized_objects.py
Lines 227 to 250 in bb5a744
The better solution would be to create these objects in tests via fixtures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think the opposite. If we add fixtures to individual tests, we'll need to keep adding more fixtures every time a new issue arises. Python's module import system is complex, making it unpredictable which module will be imported in what order. Whether a fixture is needed or not would become a black box that you can only figure out by running the tests. I believe this kind of non-determinism in tests is risky.
Regarding the performance concern you raised — for non-DB tests to run correctly, all airflow.models need to be imported eventually anyway (that's exactly why we're having this issue in the first place). The only difference is that we import them explicitly and all at once at startup — nothing more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing
airflow.modelor calling any ORM-related code is not expected in non-DB tests. Anyway, I noticed the following:TIobject only used intest_serialize_deserializeas an argument in one of test suites.TI_WITH_START_DAYandDAG_RUNare unused.I think the better compromise is:
TI,TI_WITH_START_DAYandDAG_RUNfrom the code so no global objects are used by tests.test_serialize_deserializearguments, replaceti=TIwithti=make_callback_ti(), wheremake_callback_ti()creates a datamodel object:This way we keep the code architecturally clean and without explicit ORM where ORM is not expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried the approach you suggested, but the same error I encountered still occurs.
Would you like to try it yourself?
run into shell by executing
and do test what i did
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we could probably fix it by tweaking other things as well. But should we really have to run and fix each case one by one? That approach risks breaking DB tests along the way, and it could make maintaining compatibility even harder.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check #65206
This PR doesn't introduce new ORM-related calls to
--skip-db-testsmode, but rearrange the code a bit to allow serialization tests to run in this mode. I also checked that all unit-tests in airflow-core work with--skip-db-tests, the problem is only with serialization tests.