Skip to content

The op.drop_table operation does not trigger the before_drop and after_drop events #1037

Closed
@adrien-berchet

Description

@adrien-berchet

Describe the bug
The op.drop_table operation does not trigger any event while the op.create_table does trigger the related events. This behavior is confusing for the user.

Expected behavior
The op.drop_table operation should trigger the before_drop and after_drop events for op.drop_table operation.

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.

Here is a test that can be added in tests.test_op.OpTest:

    def test_drop_table_event(self):
        context = op_fixture()

        events_triggered = []

        TestTable = Table("tb_test", MetaData(), Column("c1", Integer, nullable=False))

        @event.listens_for(Table, "before_drop")
        def record_before_event(table, conn, **kwargs):
            events_triggered.append(("before_drop", table.name))

        @event.listens_for(Table, "after_drop")
        def record_after_event(table, conn, **kwargs):
            events_triggered.append(("after_drop", table.name))

        op.create_table(TestTable)
        op.drop_table(TestTable)
        context.assert_("CREATE TABLE tb_test ()", "DROP TABLE tb_test")

        assert events_triggered == [
            ("before_drop", "tb_test"),
            ("after_drop", "tb_test"),
        ]

Error

Traceback (most recent call last):
  File "***/alembic/tests/test_op.py", line 1136, in test_drop_table_event
    assert events_triggered == [
AssertionError: assert [] == [('before_dro...', 'tb_test')]
  Right contains 2 more items, first extra item: ('before_drop', 'tb_test')
  Full diff:
  - [('before_drop', 'tb_test'), ('after_drop', 'tb_test')]
  + []

Versions.

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

Additional context
This issue is related to geoalchemy/geoalchemy2#374

Have a nice day!

Metadata

Metadata

Assignees

No one assigned

    Labels

    op directivesuse casenot quite a feature and not quite a bug, something we just didn't think of

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions