Sun-Wukhan opened a new pull request, #77564:
URL: https://github.com/apache/airflow/pull/77564

   closes: #77352
   
   `BundleVersionLock._update_version_file` intended to write the last-used 
timestamp to a temp file and atomically replace the tracking file, but it built 
the temp path as `Path(td, self.lock_file_path)`. Because `lock_file_path` is 
absolute, that Path is the tracking file itself, so the file was truncated and 
rewritten in place and a concurrent reader could observe it empty.
   
   Separately, `BundleUsageTrackingManager._parse_dt` only caught pendulum's 
`ParserError`. On pendulum 3.1 (the minimum version Airflow pins), 
`pendulum.parse("")` raises a plain `ValueError: year 0 is out of range`, so a 
single empty tracking file aborted the whole `remove_stale_bundle_versions` 
pass instead of being skipped.
   
   Changes:
   
   * `_update_version_file` now writes to a `NamedTemporaryFile` in the same 
directory as the tracking file and `os.replace`s it onto the target, with the 
temp file unlinked in a `finally` block. Same directory means same filesystem, 
so the replace is atomic and readers never see a partially written file.
   * `_parse_dt` now catches `(ParserError, ValueError)`, so empty or corrupt 
tracking files return None and are skipped by the existing log-and-continue 
path in `_find_all_tracking_files`.
   
   Tests (in `airflow-core/tests/unit/dag_processing/bundles/test_base.py`):
   
   * `_parse_dt("")` and `_parse_dt("not-a-date")` return None.
   * `_find_all_tracking_files` with one empty tracking file plus one old valid 
file does not raise and still returns the old version.
   * `_update_version_file` leaves parseable timestamp content and no leftover 
temp files in the tracking directory.
   
   Test evidence: the new tests are written for CI. Locally, the changed 
behaviour was verified against the edited module with a standalone script 
(fail-before: the old code raises ValueError on an empty tracking file and 
aborts the tracking-file scan; pass-after: the empty file is skipped and the 
old version is still returned, and the version file is written atomically). 
`ruff format` and `ruff check` pass on both edited files. The full Airflow test 
suite was not run locally.


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