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

   ### Apache Airflow version
   
   3.0.6
   
   ### If "Other Airflow 2 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   When using custom classes that subclass pathlib.PosixPath, Airflow 3's new 
SDK templating system calls .resolve(context) on these objects when rendering 
templates. If the subclass doesn't override resolve to accept a context 
argument, the method inherited from PosixPath is called, and the context (a 
dict) is interpreted as 'strict=True', causing Path.resolve(strict=True) and 
triggering FileNotFoundError if the file doesn't exist. This is a regression 
from Airflow 2.x and breaks compatibility with custom path-like objects in 
op_kwargs and other templated fields.
   
   Example error:
   ```
   FileNotFoundError: [Errno 2] No such file or directory: 
'/path/to/some/file.txt'
   File 
"/home/airflow/.local/lib/python3.11/site-packages/airflow/sdk/definitions/_internal/templater.py",
 line 192 in render_template
   File 
"/home/airflow/.local/lib/python3.11/site-packages/custom_file_lib/path.py", 
line 140 in resolve
   File "/usr/local/lib/python3.11/pathlib.py", line 993 in resolve
   ```
   
   This behavior can break any custom library that extends pathlib.Path and 
doesn't override resolve(context).
   
   ### What you think should happen instead?
   
   The templater should not call .resolve(context) on objects that inherit from 
pathlib.Path, or should handle cases where resolve is not designed for 
templating. Ideally, the templater should distinguish between 'templating 
resolution' and 'filesystem resolution'. Or, provide a clear interface so 
custom classes can be compatible without breaking existing path-like subclasses.
   
   ### How to reproduce
   
   1. Create a custom class that subclasses pathlib.PosixPath and does not 
override resolve().
   2. Pass an instance of this class as a templated field/op_kwargs in Airflow 
3.x SDK DAG.
   3. Trigger task rendering (e.g. via BashOperator or similar).
   4. Observe FileNotFoundError during template rendering if the file does not 
exist.
   
   ### Operating System
   
   Linux (Debian-based container)
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Other Docker-based deployment
   
   ### Deployment details
   
   _No response_
   
   ### Anything else?
   
   Happens every time a custom Path subclass is passed to a templated field and 
the file does not exist yet.
   
   ### Are you willing to submit PR?
   
   - [ ] 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: commits-unsubscr...@airflow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to