Skip to content

Allow configuring the collation of asset name columns - #71249

Closed
1fanwang wants to merge 5 commits into
apache:mainfrom
1fanwang:tidb-asset-collation-config
Closed

1fanwang wants to merge 5 commits into
apache:mainfrom
1fanwang:tidb-asset-collation-config

Conversation

@1fanwang

@1fanwang 1fanwang commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Fresh MySQL-compatible installs fail without latin1_general_cs. Airflow uses single-byte collation to fit 1,500-character indexes.

A database setting now controls ORM and migration collations.

Fixes #31373

Testing Done

Tested against TiDB 8.5.1.

Raw logs
$ airflow db migrate
[info] Creating Airflow database tables from the ORM
pymysql.err.OperationalError: (1273, "Unsupported collation when new collation is enabled: 'latin1_general_cs'")

$ AIRFLOW__DATABASE__SQL_ENGINE_COLLATION_FOR_ASSET_NAMES=latin1_bin airflow db migrate
[info] Creating Airflow database tables from the ORM
[info] Running stamp_revision  -> c7f0a5d2e9b4
[info] Database migration done!

$ mysql -N -B -h 127.0.0.1 -P 14000 -u root airflow_custom -e "
  SELECT CONCAT('tables=', COUNT(*))
  FROM information_schema.tables
  WHERE table_schema = 'airflow_custom';
  SELECT CONCAT(table_name, '.', column_name, '=', collation_name)
  FROM information_schema.columns
  WHERE table_schema = 'airflow_custom'
    AND (table_name LIKE 'asset%' OR table_name LIKE 'dag_schedule_asset_%_reference')
    AND column_name IN ('name', 'uri', 'group')
  ORDER BY table_name, ordinal_position"
tables=75
asset.name=latin1_bin
asset.uri=latin1_bin
asset.group=latin1_bin
asset_active.name=latin1_bin
asset_active.uri=latin1_bin
asset_alias.name=latin1_bin
asset_alias.group=latin1_bin
asset_watcher.name=latin1_bin
dag_schedule_asset_name_reference.name=latin1_bin
dag_schedule_asset_uri_reference.uri=latin1_bin

$ AIRFLOW__DATABASE__SQL_ENGINE_COLLATION_FOR_ASSET_NAMES=latin1_bin airflow db migrate --show-sql-only --from-version 2.7.0 --to-version 3.4.0 > migration.sql
$ grep -c latin1_bin migration.sql
14
$ grep -c latin1_general_cs migration.sql
0

$ uv run --project airflow-core pytest airflow-core/tests/unit/models/test_base.py airflow-core/tests/unit/migrations/test_migration_utils.py -k asset_name_collation -q
12 passed, 1 warning

$ uv run --project airflow-core pytest airflow-core/tests/unit/migrations/test_migration_utils.py::test_migration_stairway airflow-core/tests/unit/models/test_asset.py -q
9 passed, 1 warning
Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: GitHub Copilot CLI (GPT-6 Astra) following the guidelines

@1fanwang
1fanwang force-pushed the tidb-asset-collation-config branch from 2e8d220 to 9f818c2 Compare August 6, 2026 17:38
@1fanwang
1fanwang force-pushed the tidb-asset-collation-config branch 2 times, most recently from 2b1699c to ea56fea Compare August 6, 2026 19:05
@1fanwang
1fanwang marked this pull request as ready for review August 6, 2026 20:07
@1fanwang
1fanwang requested review from XD-DENG and ashb as code owners August 6, 2026 20:07
@1fanwang
1fanwang requested a review from ephraimbuddy as a code owner August 7, 2026 19:20
@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Aug 13, 2026
The asset name, uri and group columns hard-code the latin1_general_cs
collation on MySQL. Several MySQL-compatible engines do not provide that
collation, so Airflow cannot create its own schema on them even though the
rest of the database works. There is no way to override it from outside,
because the collation is baked into the ORM column definitions.

closes: apache#31373
Signed-off-by: 1fanwang <1fannnw@gmail.com>
The asset name/uri/group columns carry an explicit MySQL collation so their
1500-character unique indexes stay inside the 3072-byte index limit. That
collation is configurable on the models, but the migrations that create and
alter those columns still hard-coded `latin1_general_cs`, so the setting only
took effect when the schema was created from the ORM.

A fresh install on a MySQL-compatible engine that lacks that collation replays
the migrations instead and fails on the first asset table, which leaves the
setting useless in exactly the case it was added for.

Resolve the collation at migration run time through the same configuration key
the models read.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
The setting controls both ORM table creation and historical migrations, so both paths need focused coverage to keep unsupported hard-coded collations from returning.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
Helper tests alone would not catch a migration reverting to the unsupported hard-coded collation. Render the full MySQL migration chain with the override and assert every emitted asset collation uses it.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
Two historical downgrades recreate indexed asset columns. Render both MySQL downgrade paths with the override so an unsupported hard-coded collation cannot return there.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
@potiuk

potiuk commented Sep 25, 2026

Copy link
Copy Markdown
Member

Hello @1fanwang - thank you for your contributions to Apache Airflow!

The Airflow community has introduced a limit of 5 open pull requests at a time for contributors without write access to the repository. You currently have 34 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:

These pull requests stay open because maintainers are already engaged in them - they count towards your limit:

This is not a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are.

What we ask you to do is to make your first prioritization decision: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or gh pr reopen <PR_NUMBER> --repo apache/airflow. Reopen the ones you are ready to follow through - keep them rebased, respond to review comments and fix failing checks.

While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack.

Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ConfigTemplates closed because of open PR limit Closed as a one-time step of introducing the open pull request limit ready for maintainer review Set after triaging when all criteria pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

allow configuring dataset model uri collation

2 participants