kaxil commented on code in PR #60808:
URL: https://github.com/apache/airflow/pull/60808#discussion_r2710449965
##########
task-sdk/src/airflow/sdk/__init__.py:
##########
@@ -176,7 +179,13 @@ def __getattr__(name: str):
import importlib
mod = importlib.import_module(module_path, __name__)
- val = getattr(mod, name)
+
+ # try and get the attribute from the module
+ # if it doesn't exist (for modules like macros), return module itself
+ try:
+ val = getattr(mod, name)
+ except AttributeError:
+ val = mod
Review Comment:
I am with @shahar1 on this. This could mask any typos in `__lazy_imports`
which is very likely:
```py
# Hypothetical typo in __lazy_imports:
"DAG_typo": ".definitions.dag",
# Before this PR:
from airflow.sdk import DAG_typo
# AttributeError: module 'airflow.sdk.definitions.dag' has no attribute
'DAG_typo'
# Clear error pointing to the problem
# After this PR:
from airflow.sdk import DAG_typo
# No error - silently returns the module object
DAG_typo(dag_id="test")
# TypeError: 'module' object is not callable
# Confusing error that doesn't point to the real issue
```
A rather simpler solution would be instead of modifying `__getattr__`, just
expose macros in `execution_time/__init__.py`:
```py
# task-sdk/src/airflow/sdk/execution_time/__init__.py
from airflow.sdk.execution_time import macros
```
Then change the lazy import to:
```py
"macros": ".execution_time",
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]