bramhanandlingala opened a new pull request, #67426:
URL: https://github.com/apache/airflow/pull/67426
## Issue
When you configure Airflow with multiple executors and only some of them opt
in to `pre_assigns_external_executor_id` (like CeleryExecutor does), the
scheduler builds a SQL `CASE` expression to decide which task instances get a
UUID assigned:
```sql
CASE
WHEN task_instance.executor IN ('celery', 'celery.module.path') THEN
gen_random_uuid()
ELSE task_instance.external_executor_id
END
```
PostgreSQL takes one look at this and bails: "CASE types text and uuid
cannot be matched". The THEN branch returns a native UUID type (that's what
gen_random_uuid() produces in PostgreSQL), but the ELSE branch returns TEXT.
because external_executor_id was changed from VARCHAR to TEXT in migration
0102. Postgres won't implicitly coerce between the two.
MySQL and SQLite are fine, their UUID() / uuid4() functions already return
plain strings.
## The Fix
One line in the PostgreSQL compiler for random_db_uuid:
# before
return "gen_random_uuid()"
# after
return "gen_random_uuid()::text"
Casting to ::text makes the THEN branch the same type as the ELSE branch.
This also matches what random_db_uuid already declares as its SQLAlchemy type
(type = String()), so this was always the intended behaviour. the cast was just
missing.
## Test
Added
test_executable_task_instances_to_queued_mixed_executors_external_executor_id
which wires up two executors (one opt-in, one not), routes task instances to
each, and calls _executable_task_instances_to_queued. On PostgreSQL this
directly exercises the CASE path that was crashing. The test also asserts that
only the TI routed to the opt-in executor gets a UUID, and the other keeps None.
Are you willing to merge this PR?
Yes If it helps
Code of Conduct
I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
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]