Skip to content

Alembic Batch Operations and Partial Ordering Bug #923

Open
@shdai12

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions