kaxil commented on code in PR #60808:
URL: https://github.com/apache/airflow/pull/60808#discussion_r2710456214


##########
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:
   The airflow-core version (`airflow-core/src/airflow/__init__.py) is 
different - it uses a tuple `(module_path, attr_name, deprecated)` where an 
empty `attr_name` explicitly signals "return the module itself":
   
   ```py
   "version": (".version", "", False),  # Empty string = return module
   "metrics": (".observability.metrics", "", True),  # Empty string = return 
module
   ```
   
   The check is explicit:
   ```
   if attr_name:
       val = getattr(mod, attr_name)
   else:
       val = mod
   ```
   
   whereas this PR uses a `try/except` fallback which is implicit - it catches 
`AttributeError` for any reason and assumes "return the module". The 
airflow-core pattern is intentional, yours is a fallback that could hide bugs.
   



##########
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:
   The airflow-core version (`airflow-core/src/airflow/__init__.py) is 
different - it uses a tuple `(module_path, attr_name, deprecated)` where an 
empty `attr_name` explicitly signals "return the module itself":
   
   ```py
   "version": (".version", "", False),  # Empty string = return module
   "metrics": (".observability.metrics", "", True),  # Empty string = return 
module
   ```
   
   The check is explicit:
   ```py
   if attr_name:
       val = getattr(mod, attr_name)
   else:
       val = mod
   ```
   
   whereas this PR uses a `try/except` fallback which is implicit - it catches 
`AttributeError` for any reason and assumes "return the module". The 
airflow-core pattern is intentional, yours is a fallback that could hide bugs.
   



-- 
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]

Reply via email to