sqlalchemy / sqlalchemy/alembic

Migration autogeneration should respect schemas defined using quoted_name

Open
#1,526 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autogenerate - rendering bug code review in progress
Dominant language
Python
Stars
4.4k
Forks
375
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
When defining a table, schemas defined using quoted_name should be present on the migration generated code.

Expected behavior
The schema present in the migration file should be defined using quoted_name too

To Reproduce
Define a class using the snipped provided, then run alembic revision --autogenerate and check the generated migration operations

from sqlalchemy.orm import DeclarativeBase
from sqlalchemy import quoted_name

class Base(DeclarativeBase):
    pass

class Example(Base):
    __table_args__ = {'schema': quoted_name('database.schema', quote=False)}
    example_field = Column(Integer, primary_key=True)

Actual behaviour

    op.create_table('example',
    sa.Column('example_field', sa.Integer()),
    sa.PrimaryKeyConstraint('account_id'),
    schema='database.schema'
    )

Expected behaviour

    op.create_table('example',
    sa.Column('example_field', sa.Integer()),
    sa.PrimaryKeyConstraint('account_id'),
    schema=quoted_name('database.schema', quote=False)
    )

Versions.

  • OS: Mac
  • Python:3.12
  • Alembic: 1.13.2
  • SQLAlchemy: 2.0.32
  • Database: Databricks

Additional context
Im using the databricks sql connector 3.3.0

Have a nice day!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided DeclarativeBase and quoted_name example, then run alembic revision --autogenerate and inspect the generated migration operations. Trace the autogeneration path that renders the table schema; done means the generated migration preserves quoted_name('database.schema', quote=False) rather than emitting a plain string.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlalchemy
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.