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

AttributeError when removing an event in SQLAlchemy 1.2.3 #4190

Closed
sqlalchemy-bot opened this issue Feb 19, 2018 · 8 comments
Closed

AttributeError when removing an event in SQLAlchemy 1.2.3 #4190

sqlalchemy-bot opened this issue Feb 19, 2018 · 8 comments
Labels
blocker issue that must be resolved asap as it is preventing things from working bug Something isn't working engine engines, connections, transactions, isolation levels, execution options
Milestone

Comments

@sqlalchemy-bot
Copy link
Collaborator

Migrated issue, originally created by href (@href)

When removing a registered Event on the Engine class in SQLAlchemy 1.2.3 I get an AttributeError.

Code:

from sqlalchemy import event
from sqlalchemy.engine import Engine

@event.listens_for(Engine, 'after_cursor_execute')
def after_cursor_execute(*args, **kwargs):
    pass

event.remove(Engine, 'after_cursor_execute', after_cursor_execute)

Setup:

python3.6 -m venv test
cd test
bin/pip install sqlalchemy
bin/python test.py

Stacktrace:

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    event.remove(Engine, 'after_cursor_execute', after_cursor_execute)
  File "/private/tmp/test/lib/python3.6/site-packages/sqlalchemy/event/api.py", line 178, in remove
    _event_key(target, identifier, fn).remove()
  File "/private/tmp/test/lib/python3.6/site-packages/sqlalchemy/event/registry.py", line 220, in remove
    collection.remove(self.with_wrapper(listener_fn))
  File "/private/tmp/test/lib/python3.6/site-packages/sqlalchemy/event/attr.py", line 167, in remove
    self._clslevel[cls].remove(event_key._listen_fn)
AttributeError: '_empty_collection' object has no attribute 'remove'

Only SQLAlchemy 1.2.3 seems to be affected. 1.2.2 works. I'm using Python 3.6 on MacOS High Sierra. Additionally I use Psycopg2.7.4 and Postgres 10.1, though from what I can tell that is not relevant here since I can reproduce the error in a clean virtualenv.

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by href (@href):

  • edited description

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

I know what this is and you should be able to use 1.2.2. I am very much hoping to fix and release 1.2.4 today however other issues seem like they are going to make this more challenging to achieve.

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • added labels: blocker

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • set milestone to "1.2.x"

@sqlalchemy-bot
Copy link
Collaborator Author

href (@href) wrote:

I'm absolutely okay using 1.2.2 and have in fact already added sqlalchemy!=1.2.3 to my requirements. No pressure from my side ;)

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

Implement remove() for _empty_collection

Fixed regression caused in 1.2.3 due to fix from 🎫4181 where
the changes to the event system involving :class:.Engine and
:class:.OptionEngine did not accommodate for event removals, which
would raise an AttributeError when invoked at the class
level.

Change-Id: I1c9083829d74dd710716d28b0eaca4fa15e86313
Fixes: #4190

1393eac

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot
Copy link
Collaborator Author

href (@href) wrote:

Thank you!

@sqlalchemy-bot sqlalchemy-bot added bug Something isn't working blocker issue that must be resolved asap as it is preventing things from working engine engines, connections, transactions, isolation levels, execution options labels Nov 27, 2018
@sqlalchemy-bot sqlalchemy-bot added this to the 1.2.x milestone Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker issue that must be resolved asap as it is preventing things from working bug Something isn't working engine engines, connections, transactions, isolation levels, execution options
Projects
None yet
Development

No branches or pull requests

1 participant