1fanwang opened a new pull request, #71258:
URL: https://github.com/apache/airflow/pull/71258
The MySQL branch of this downgrade passes two statements to a single
`op.execute()`:
```python
op.execute(
"""
SET @row_number = 0;
UPDATE task_instance_history
SET id = (@row_number := @row_number + 1)
ORDER BY try_id;
"""
)
```
PyMySQL does not enable `CLIENT.MULTI_STATEMENTS`, so it rejects the script
with a syntax error and the downgrade cannot run. mysqlclient does enable it,
which is why the problem is invisible to anyone on that driver, including CI:
`scripts/ci/docker-compose/backend-mysql.yml` uses a bare `mysql://` URL, which
SQLAlchemy resolves to `mysqldb`.
Splitting into two `op.execute()` calls fixes it. `op.execute()` reuses
`op.get_bind()`, so `@row_number` is still visible to the `UPDATE`.
Same class of bug as PR https://github.com/apache/airflow/pull/70235, which
fixes the multi-statement SQL in `0017_2_9_2`. I found this one while looking
at that PR. The two do not overlap.
### Testing Done
MySQL 8.4, the migration's own SQL against both drivers, before and after.
<details><summary>Raw logs</summary>
Table seeded with `try_id` out of order (`30, 10, 20`) so the renumbering is
observable:
```
CURRENT OK mysqlclient -> [(10, 1), (20, 2), (30, 3)]
CURRENT FAIL PyMySQL ProgrammingError:
(pymysql.err.ProgrammingError) (1064,
"You have an error in your SQL syntax; check
the manual t...")
FIXED OK mysqlclient -> [(10, 1), (20, 2), (30, 3)]
FIXED OK PyMySQL -> [(10, 1), (20, 2), (30, 3)]
```
The fix produces identical numbering on both drivers, confirming the session
variable survives across the two calls and the `ORDER BY try_id` sequencing is
unchanged.
</details>
Static checks pass, including `Update migration ref doc` and
`mypy-airflow-core`.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — GitHub Copilot CLI (Claude Opus 5)
Generated-by: GitHub Copilot CLI (Claude Opus 5) 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]