sqlalchemy / sqlalchemy/alembic
Example change for branched connection still doesn't work
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
From https://alembic.sqlalchemy.org/en/latest/cookbook.html#sharing-a-connection-with-a-series-of-migration-commands-and-environments there is this snippet:
def run_migrations_online():
connectable = config.attributes.get('connection', None)
if connectable is None:
# only create Engine if we don't have a Connection
# from the outside
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
context.configure(
connection=connectable,
target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
but connectable is then an engine when there isn't one in the config. The error is:
'connection' argument to configure() is expected to be a sqlalchemy.engine.Connection instance, got Engine(postgresql://pydiscos3test:***@postgres/discos3)
Versions.
- OS: N/A
- Python: 3.7
- Alembic: 1.7.3
- SQLAlchemy: 1.4.23
- Database: PostgreSQL
- 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 the branched-connection example in the Alembic cookbook and inspect the run_migrations_online() flow around context.configure(). Reproduce the reported Engine-versus-Connection error, then verify that the example works both with an externally supplied connection and when no connection is configured.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python, sqlalchemy
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100