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

   ### Under which category would you file this issue?
   
   Airflow Core.
   
   ### Apache Airflow version
   
   3.3.2. The same code is on `main` and in 3.4.0rc3.
   
   ### What happened and how to reproduce it?
   
   If a Dag is packaged in a zip file, its Dag-level `on_success_callback` and 
`on_failure_callback` never run. The Dag processor child process crashes before 
it gets to the callback.
   
   A Dag callback request carries the Dag's file path inside the archive, for 
example `/opt/airflow/dags/my_dags.zip/main.py`. `_parse_file` passes this path 
to `check_dag_file_stability`, which calls `Path(file_path).read_bytes()`. The 
archive is a file, not a directory, so the read raises `NotADirectoryError`. 
The checker catches only `(SyntaxError, ValueError, TypeError, 
FileNotFoundError)`, so the exception reaches the supervisor and the child 
exits with code 126:
   
   ```
   --- Supervised process Last chance exception handler ---
   Traceback (most recent call last):
     File ".../airflow/sdk/execution_time/supervisor.py", line 459, in 
_fork_main
       target()
     File ".../airflow/dag_processing/processor.py", line 228, in 
_parse_file_entrypoint
       result = _parse_file(msg, log)
     File ".../airflow/dag_processing/processor.py", line 237, in _parse_file
       stability_check_result = check_dag_file_stability(os.fspath(msg.file))
     File ".../airflow/utils/dag_version_inflation_checker.py", line 595, in 
check_dag_file_stability
       parsed = ast.parse(Path(file_path).read_bytes())
     File ".../pathlib.py", line 1019, in read_bytes
       with self.open(mode='rb') as f:
     File ".../pathlib.py", line 1013, in open
       return io.open(self, mode, buffering, encoding, errors, newline)
   NotADirectoryError: [Errno 20] Not a directory: 
'/opt/airflow/dags/my_dags.zip/main.py'
   ```
   
   The callback log `dag_processor/<date>/<bundle>/my_dags.zip/main.py.log` 
shows only:
   
   ```
   {"level":"warning","event":"Process exited 
abnormally","exit_code":126,"logger":"processor"}
   ```
   
   "Executing on_success dag callback" is never logged, and the callback 
request is gone from the `callback` table, so the callback is lost without a 
retry.
   
   To reproduce:
   
   1. Put a Dag with a Dag-level `on_success_callback` into `my_dags.zip` (for 
example as `main.py`) in the Dags folder.
   2. Leave `[dag_processor] dag_version_inflation_check_level` at its default.
   3. Trigger the Dag and let the run succeed.
   4. The callback does not run, and the Dag processor logs the traceback above.
   
   A normal parse of the same zip does not crash, because that request carries 
the `.zip` path itself (see #73739). Task-level callbacks are not affected, 
because they run in the task process.
   
   ### What you think should happen instead?
   
   The callback runs. If `msg.callback_requests` is not empty, `_parse_file` 
ignores the stability result. So there are two possible fixes:
   
   - If the request has callback requests, skip `check_dag_file_stability`.
   - Make `check_dag_file_stability` handle a path inside an archive, or catch 
`OSError`.
   
   #74051 does not fix this case. `zipfile.is_zipfile("my_dags.zip/main.py")` 
returns `False`, so the path still goes to `read_bytes()` with the same narrow 
`except`.
   
   Workaround: set `[dag_processor] dag_version_inflation_check_level = off`. 
The check then returns before it reads the file.
   
   ### Operating System
   
   Debian 12 (official image based)
   
   ### Deployment
   
   Other 3rd-party Helm chart
   
   ### Apache Airflow Provider(s)
   
   _No response_
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Official Helm Chart version
   
   Not Applicable
   
   ### Kubernetes Version
   
   _No response_
   
   ### Helm Chart configuration
   
   _No response_
   
   ### Docker Image customizations
   
   Custom image based on `apache/airflow:3.3.2`.
   
   ### Anything else?
   
   Related: #73739 (the same check reads the zip bytes on a normal parse), 
#70987 (callbacks must not be blocked by the version inflation check).
   
   ### 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
   


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