Skip to content
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

Only load distribution of a name once #25296

Merged
merged 1 commit into from Aug 3, 2022

Conversation

uranusjr
Copy link
Member

This mimics the import system's behavior -- package of a name in front of sys.path "shadows" the one in the back, and should avoid a package from being loaded multiple times, if its containing directory appears multiple times in sys.path.

This also causes a side effect: if there are different plugins of the same name, previously the one later in sys.path would have been discovered, but now it wouldn't. I think this is a reasonable compromise, since loading multiple packages of one same name is never a good idea in
Python in the first place, and we should have been careful to preclude the possibility to begin with.

Should fix #25271. cc @rino0601 @bmoon4

Copy link
Member

@ashb ashb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks okay, but (I think) we need to expand the tests to cover this behaviour?

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Tests woudl be good..

@uranusjr
Copy link
Member Author

uranusjr commented Aug 2, 2022

I’ve added a test for the function.

@potiuk potiuk requested a review from ashb August 2, 2022 11:20
@potiuk
Copy link
Member

potiuk commented Aug 2, 2022

Tests failing :(

self.dist = dist.metadata['name']
self.dist = dist.metadata['Name']
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python pacakge metadata keys are case-insensitive, I use Name (the case used by the standard) everywhere so tests are easier to write.

This mimics the import system's behavior -- package of a name in front
of sys.path "shadows" the one in the back, and should avoid a package
from being loaded multiple times, if its containing directory appears
multiple times in sys.path.

This also causes a side effect: if there are *different* plugins of the
same name, previously the one later in sys.path would have been
discovered, but now it wouldn't. This is a reasonable compromise to me,
since loading multiple packages of one same name is never a good idea
in Python, and we should have been careful to preclude the possibility
to begin with.
@potiuk
Copy link
Member

potiuk commented Aug 3, 2022

Looks green now. @ashb ?

@uranusjr uranusjr merged commit c30dc5e into apache:main Aug 3, 2022
@uranusjr uranusjr deleted the avoid-dist-double-load branch August 3, 2022 13:01
@eladkal eladkal added this to the Airflow 2.3.4 milestone Aug 3, 2022
@ephraimbuddy ephraimbuddy added the type:bug-fix Changelog: Bug Fixes label Aug 15, 2022
ephraimbuddy pushed a commit that referenced this pull request Aug 15, 2022
jedcunningham pushed a commit to astronomer/airflow that referenced this pull request Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 2.3.3 breaks "Plugins as Python packages" feature
5 participants