sqlalchemy / sqlalchemy/alembic

Naming conventions in metadata sequences are ignored

Open
#1,396 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

Metadata sequences were implemented in #38, only for auto generation, in 7d5f6eabeccb9328c1c21dd0cdf9ff1f2f85836d.

The SchemaObjects.metadata() is older than the sequences implementation and don't check if it is a list. https://github.com/sqlalchemy/alembic/blob/main/alembic/operations/schemaobj.py#L193-L202

Expected behavior

Naming conventions should be respected with metadata sequences.

To Reproduce
Please try to provide a Minimal, Complete, and Verifiable example, with the migration script and/or the SQLAlchemy tables or models involved.
See also Reporting Bugs on the website.

from sqlalchemy import MetaData
from alembic.config import Config
from alembic.operations.schemaobj import SchemaObjects
from alembic.runtime.environment import EnvironmentContext
from alembic.script import ScriptDirectory

convention = {
    "ix": "foo_ix_%(table_name)s_%(column_0_name)s",
}

context = EnvironmentContext(Config(), ScriptDirectory("."))
context.configure(
    dialect_name="postgresql",
    target_metadata=[
        MetaData(naming_convention=convention),
        MetaData(),
    ],
)
# This is unexpectedly the default naming convention `immutabledict({'ix': 'ix_%(column_0_label)s'})`
print(SchemaObjects(context.get_context()).metadata().naming_convention)

context = EnvironmentContext(Config(), ScriptDirectory("."))
context.configure(
    dialect_name="postgresql",
    target_metadata=MetaData(naming_convention=convention),
)
# It works as expected
print(SchemaObjects(context.get_context()).metadata().naming_convention)

Error

There is no error, but it doesn't use my conventions.

Versions.

  • OS:
  • Python:
  • Alembic:
  • SQLAlchemy:
  • Database:
  • DBAPI:

Additional context

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

Start with alembic/operations/schemaobj.py around lines 193-202 and run the reproduction using SchemaObjects.metadata() with a list of MetaData objects. Compare the list and single-MetaData cases; done means the configured naming convention is preserved when metadata sequences are used.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.