KushagraB424 opened a new issue, #71198:
URL: https://github.com/apache/airflow/issues/71198

   ### Under which category would you file this issue?
   
   Airflow Core
   
   ### Apache Airflow version
   
   main
   
   ### What happened and how to reproduce it?
   
   **Issue Description**
   The `__getattr__` fallback in `airflow.utils.helpers` is designed to provide 
backward compatibility for deprecated functions that have moved (like 
`render_template_as_native`). However, it currently fails and throws an 
`AttributeError` when any of those functions are accessed.
   
   This happens because the fallback dynamically loads the new module using 
`__import__(modpath)`. When `modpath` is a dotted path (e.g., 
`"airflow.sdk.definitions.context"`), Python's `__import__` without the 
`fromlist` argument returns the root package (`airflow`), not the leaf module. 
The subsequent `getattr` call then tries to find the function on the root 
`airflow` module, which fails.
   
   **Steps to reproduce:**
   Run the following in a Python shell:
   ```python
   import airflow.utils.helpers
   # Attempt to access a deprecated function that has moved to a dotted module 
path
   airflow.utils.helpers.render_template_as_native
   ```
   This incorrectly produces the following error:
   
   AttributeError: module 'airflow' has no attribute 'render_template_as_native'
   
   ### What you think should happen instead?
   
   Instead of raising an `AttributeError`, the `__getattr__` fallback should 
properly resolve the leaf module, trigger the `DeprecationWarning`, and return 
the requested function. 
   This can be easily fixed by using `importlib.import_module(modpath)` instead 
of `__import__(modpath)`. 
   *(Note: I already have a PR ready to submit for this fix!)*
   
   ### Operating System
   
   Not Applicable
   
   ### Deployment
   
   None
   
   ### Apache Airflow Provider(s)
   
   _No response_
   
   ### Versions of Apache Airflow Providers
   
   Not Applicable
   
   ### Official Helm Chart version
   
   Not Applicable
   
   ### Kubernetes Version
   
   Not Applicable
   
   ### Helm Chart configuration
   
   Not Applicable
   
   ### Docker Image customizations
   
   Not Applicable
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


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