sqlalchemy / sqlalchemy/alembic
Naming conventions in metadata sequences are ignored
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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