- changed status to duplicate
TypeError when removing a connection event
Issue #2686
resolved
When removing a connection event:
from sqlalchemy import create_engine
from sqlalchemy import event
engine = create_engine('sqlite:///')
connection = engine.connect()
@event.listens_for(connection, 'after_cursor_execute')
def after_cursor_execute(conn, cursor, statement, parameters, context, executemany):
pass
event.remove(connection, 'after_cursor_execute', after_cursor_execute)
I see the following error:
$ bin/py connection_event_bug.py
Traceback (most recent call last):
File "bin/py", line 61, in <module>
exec(compile(__file__f.read(), __file__, "exec"))
File "connection_event_bug.py", line 12, in <module>
event.remove(connection, 'after_cursor_execute', after_cursor_execute)
File "/Users/lrowe/.buildout/eggs/SQLAlchemy-0.8.0-py2.7-macosx-10.6-intel.egg/sqlalchemy/event.py", line 76, in remove
for tgt in evt_cls._accept_with(target):
TypeError: 'Connection' object is not iterable
Though this does work:
connection.dispatch.after_cursor_execute.remove(after_cursor_execute, connection)
Comments (1)
-
repo owner - Log in to comment
yeah, removal of events is basically a TODO at this point - we do it within some of our tests but we do it by clearing out the dispatch dictionaries entirely. removal is in some cases less than trivial due to the way events propagate to related objects; we'd have to locate all those propagated locations as well when an event is removed.
#2268exists as the ticket for this particular task.