Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix column reflection in SQLAlchemy 2.0 #277

Merged
merged 1 commit into from
Dec 8, 2023

Conversation

littlebtc
Copy link
Contributor

Running alembic revision --autogenerate with SQLAlchemy 2.0.23 and Alembic 1.12.1 with existing table will miss all columns, resulting in errors like that if you have any engine configuration related to columns:

sqlalchemy.exc.ConstraintColumnNotFoundError: Can't create KeysExpressionOrColumn on table 'table': no column named 'column' is present.

In my code with ReplacingMergeTree engine and order_by set, It crashes here as the parent.c is empty; after tracing the code, it seems that the Table is heavily refactored in SQLAlchemy 2.0, and internally it will use table.c to access the columns. This PR added .c clones to _make_from_standard, making the --autogenerate works for me.

I also hit #275, and I managed to bypass it by adding a patched patch_alembic_version in the env.py.

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Ensure PR doesn't contain untouched code reformatting: spaces, etc.
  • Run flake8 and fix issues.
  • Run pytest no tests failed. See https://clickhouse-sqlalchemy.readthedocs.io/en/latest/development.html.

@xzkostyan xzkostyan merged commit 5d25149 into xzkostyan:master Dec 8, 2023
16 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants