-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Fix __getattr__ in helpers.py throwing AttributeError for dotted module paths #71199
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -313,11 +313,12 @@ def __getattr__(name: str): | |
| except KeyError: | ||
| raise AttributeError(f"module '{__name__}' has no attribute '{name}'") from None | ||
|
|
||
| import importlib | ||
| import warnings | ||
|
|
||
| warnings.warn( | ||
| f"{__name__}.{name} is deprecated. Use {modpath}.{name} instead.", | ||
| DeprecationWarning, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We already have from airflow.utils.deprecation_tools import add_deprecated_classes
add_deprecated_classes(
{
__name__: {
"render_template_as_native": "airflow.sdk.definitions.context.render_template_as_native",
"render_template_to_string": "airflow.sdk.definitions.context.render_template_to_string",
"prevent_duplicates": "airflow.sdk.definitions.mappedoperator.prevent_duplicates",
}
},
package=__name__,
)which lets both |
||
| stacklevel=2, | ||
| ) | ||
| return getattr(__import__(modpath), name) | ||
| return getattr(importlib.import_module(modpath), name) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a regression test? @pytest.mark.parametrize(
"name", ["render_template_as_native", "render_template_to_string", "prevent_duplicates"]
)
def test_deprecated_imports_resolve(name):
with pytest.warns(DeprecationWarning):
assert getattr(helpers, name) is not NoneNothing in the tree touches |
||
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.
Minor:
importlibis part of the import machinery and always loaded, so this can sit at the top of the file with the rest of the imports. Moot if you take theadd_deprecated_classesroute above.