steveahnahn opened a new pull request, #72979:
URL: https://github.com/apache/airflow/pull/72979

   `airflow db downgrade` from 3.3 destroys deadline alerts whose interval is 
not a plain timedelta. With a `VariableInterval` row present, Postgres aborts 
mid-migration, MySQL corrupts the value and then fails the column retype after 
the implicit commit has persisted the corruption, and SQLite silently converts 
the interval to `0.0`, a deadline that fires immediately after the downgrade.
   
   Verified by seeding one serialized `VariableInterval` (the exact shape Dag 
parsing stores) and running the real `airflow db downgrade`:
   
   ```
   sqlalchemy.exc.IntegrityError: (psycopg.errors.NotNullViolation) null value 
in column
   "interval" of relation "deadline_alert" violates not-null constraint
   ```
   
   ### Root cause
   
   The previous schema stores intervals as FLOAT NOT NULL, so only numbers and 
serialized `datetime.timedelta` values can be converted back. The conversion 
CASE maps everything else to NULL, and the in-file comment claiming such values 
"will cast as null" cannot be true against a NOT NULL column.
   
   ### Fix
   
   A pre-flight check reads the table (one row per alert definition, so this is 
cheap and dialect-free) and refuses the downgrade with the affected alert ids 
before any value is modified on any backend, in particular before MySQL's 
implicitly committing UPDATE. Deployments without such intervals are 
unaffected; the clean path still converts a serialized 5-minute timedelta to 
`300.0`. Re-run of the same seed after the fix:
   
   ```
   RuntimeError: Cannot downgrade: 1 deadline alert(s) use a serialized 
interval with no float
   representation: id=... (airflow.sdk.definitions.deadline.VariableInterval). 
The previous schema
   stores intervals as float seconds. Delete these deadline alerts or change 
their interval to a
   timedelta, then re-run the downgrade.
   ```
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Fable 5.1)
   
   Generated-by: Claude Code (Fable 5.1) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


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