Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
adrien-berchet opened this issue May 16, 2022 · 2 comments
Labels
op directives use case not quite a feature and not quite a bug, something we just didn't think of

Comments

@adrien-berchet
Copy link
Contributor

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!

@adrien-berchet adrien-berchet added the requires triage New issue that requires categorization label May 16, 2022
@zzzeek zzzeek added op directives use case not quite a feature and not quite a bug, something we just didn't think of and removed requires triage New issue that requires categorization labels May 17, 2022
@sqla-tester
Copy link
Collaborator

Adrien Berchet has proposed a fix for this issue in the main branch:

Trigger events before and after drop table statements https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/3882

1 similar comment
@sqla-tester
Copy link
Collaborator

Adrien Berchet has proposed a fix for this issue in the main branch:

Trigger events before and after drop table statements https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/3882

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
op directives use case not quite a feature and not quite a bug, something we just didn't think of
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants