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

   ### Under which category would you file this issue?
   
   Airflow Core
   
   ### Apache Airflow version
   
   3.3.2 (also present on `main` as of e42b5a92ae)
   
   ### What happened and how to reproduce it?
   
   With the MySQL metadata DB and **mysqlclient 2.3.1** (released 2026-11-10), 
the scheduler crash-loops with:
   
   ```
   AssertionError: No such polymorphic_identity 'CallbackType.TRIGGER' is 
defined
   ```
   
   raised from the deadline query in `SchedulerJobRunner._run_scheduler_loop` 
(`selectinload(Deadline.callback)`).
   
   mysqlclient 2.3.1 changed `Connection.literal()` from `isinstance(o, str)` 
to `type(o) is str` ("built-in handling only applies to exact built-in types; 
subclasses use the connection's converter mapping"). A `str`-subclass Enum 
without `__str__` now falls through and is escaped via `str()`, i.e. 
`CallbackType.TRIGGERER` is bound as `'CallbackType.TRIGGERER'`:
   
   ```python
   >>> conn = engine.raw_connection()
   >>> conn.literal(CallbackType.TRIGGERER)   # mysqlclient 2.3.1
   b"'CallbackType.TRIGGERER'"
   >>> conn.literal(CallbackType.TRIGGERER)   # mysqlclient 2.3.0
   b"'triggerer'"
   ```
   
   `callback.type` is `String(20)`, so with a non-strict `sql_mode` MySQL 
truncates it to `'CallbackType.TRIGGER'`, which matches no polymorphic 
identity. `callback.fetch_method` is stored as `'CallbackFetchMethod.'` the 
same way. Every DAG run with a deadline creates such a row, so the scheduler 
keeps crashing until the rows are repaired. (With a strict `sql_mode` the 
insert fails instead.)
   
   To reproduce: MySQL backend, `mysqlclient==2.3.1`, a DAG with a 
`DeadlineAlert`. Trigger a run and inspect `select type, fetch_method from 
callback`.
   
   We hit this in production. Repair after pinning the driver back to 2.3.0:
   
   ```sql
   UPDATE callback SET type='triggerer',     fetch_method='import_path'   WHERE 
type='CallbackType.TRIGGER';
   UPDATE callback SET type='dag_processor', fetch_method='dag_attribute' WHERE 
type='CallbackType.DAG_PRO';
   ```
   
   ### What you think should happen instead?
   
   Enum members bound to DB columns should be stored as their `.value`, 
regardless of driver. `CallbackState`, `TaskInstanceState`, `DagRunState` etc. 
already define `__str__` returning `self.value`, which is why their columns 
were unaffected.
   
   The same gap exists for these `str`-Enums that are written to DB columns 
without `.value`:
   
   - `CallbackType` (`callback.type`, via `polymorphic_identity`)
   - `CallbackFetchMethod` (`callback.fetch_method`)
   - `ReprocessBehavior` (`backfill.reprocess_behavior`)
   - `BackfillDagRunExceptionReason` (`backfill_dag_run.exception_reason`)
   
   (`DagWarningType` is safe: `get_warning_type_value` stores `.value`.)
   
   Postgres is unaffected: psycopg adapts `str` subclasses by their string 
value.
   
   ### Operating System
   
   Debian (official-image based)
   
   ### Deployment
   
   Other 3rd-party Helm chart
   
   ### Anything else?
   
   Workaround: pin `mysqlclient<2.3.1` (Airflow's official constraints pin 
2.2.8, so constraint-based installs are not affected).
   
   ### 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]

  • [I] Scheduler crash loop on My... styndall (via GitHub) via commits

Reply via email to