sqlalchemy / sqlalchemy/alembic
Alembic Batch Operations and Partial Ordering Bug
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
with op.batch_alter_table(
"some_table", recreate="always",
partial_reordering=[("c", "d", "a", "b")]
) as batch_op:
pass
This function and the partial_reordering parameter failed to recreate a complete reordering for all columns in the tables. The column orders are shuffled in the table. Some columns are reordered, while others are not.
with op.batch_alter_table(
"some_table", recreate="always",
partial_reordering=[("d", "c"), ("b", "a")]
) as batch_op:
pass
This function seems to change the partial ordering of columns and works fine. If we can specify a position to insert the column in the query, this would help a lot with our work.
To Reproduce
The table design is a Postgres relational schema with structured rows and columns. The exact argument passed into the table is as below:
from alembic import op
def upgrade():
conn = op.get_bind()
conn.execute("""
ALTER TABLE or_case_feed ADD COLUMN delay_reason1 STRING;
""")
with op.batch_alter_table(
"or_case_feed", recreate="always",
partial_reordering=[("run_id", "log_id", "log_id2", "room", "location", "patient_info1", "patient_info2", "delay_reason1",
"delay_comment1", "patient_info1")]
) as batch_op:
pass
Expected output has column order as ("run_id", "log_id", "log_id2", "room", "location", "patient_info1", "patient_info2", "delay_reason1", "delay_comment1", "patient_info1")
Actual output has column order as ("run_id", "log_id", "delay_comment1", "log_id2", "room", "patient_info1", "patient_info2", "delay_reason1", "location", "patient_info1")
The actual output stays the same each time.
Error
The ordering of columns following an unknown order.
Versions
- OS:
- Python: 3.6
- SQLAlchemy: 1.1.18
- Database: Postgres
- DBAPI:
Additional context
No response
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 at the op.batch_alter_table entry point and its partial_reordering handling, then reproduce the supplied examples against PostgreSQL. Done means the requested column order is applied deterministically, including the complete and multiple-partial-order cases, with regression coverage for the reported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python, sqlalchemy
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100