Correction, Connection-level event listeners is a feature add in 0.8 and was ticket #2511.
Same advice, please associate a single event listener with Engine. On Sep 26, 2012, at 1:29 PM, Michael Bayer wrote: > this is ticket #2575, only applies to 0.7 and not 0.8, and will be fixed > today. > > In the meantime, please use the format that I gave you - a single, fixed > event listener on the Engine class, established at the module level. The > assertion logic then subscribes a "listen" function inside a collection > accessed by the event listener. > > > > On Sep 26, 2012, at 1:19 PM, Ladislav Lenart wrote: > >> Hello. >> >> Call to event.listen(self.connection,...) fails with: >> >> InvalidRequestError: No such event 'before_cursor_execute' for target... >> >> because self.connection does not have 'dispatch' attribute: >> >> def listen(target, identifier, fn, *args, **kw): >> for evt_cls in _registrars[identifier]: >> # A target must have dispatch attribute as required >> # by Events._accept_with class method. >> tgt = evt_cls._accept_with(target) >> if tgt is not None: >> tgt.dispatch._listen(tgt, identifier, fn, *args, **kw) >> return >> raise exc.InvalidRequestError("No such event '%s' for target '%s'" % >> >> As I have written, the only two objects in the setUp method that the function >> event.listen accepts are self.engine and type(self.engine). >> >> Any other idea what am I doing wrong? >> >> Ladislav Lenart >> >> >> On 26.9.2012 19:07, Michael Bayer wrote: >>> >>> On Sep 26, 2012, at 12:36 PM, Ladislav Lenart wrote: >>> >>>> Hello. >>>> >>>>> I can guarantee you all SQL goes through the same channels. >>>> >>>> No doubts there :-) >>>> >>>> >>>>> perhaps you registered the event with a specific Engine or Connection >>>>> that is >>>> not the one involved in the test. >>>> >>>> This might be it, but I don't know what should I supply instead. I have the >>>> following setUp: >>>> >>>> class DbTestCase(object): >>>> def setUp(self): >>>> self.Base = create_base() >>>> self._create_db() >>>> self.connection = self.engine.connect() >>>> self.trans = self.connection.begin() >>>> self.session = Session(bind=self.connection, autoflush=False) >>>> self._sql_emitters = set() >>>> event.listen( >>>> self.engine, >>>> "before_cursor_execute", >>>> self._before_cursor_execute >>>> ) >>>> >>>> I have tried every object (and its type) present in the setUp method, but >>>> all >>>> fail with >>>> >>>> InvalidRequestError: No such event 'before_cursor_execute' for target... >>> >>> you've got self.connection already. so you want to listen on that: >>> >>> event.listen(self.connection, ...) >>> >>> when a Connection is constructed, it takes a snapshot of the event >>> listeners associated with its parent Engine. This is for performance >>> reasons so that event dispatch doesn't need to check two separate dispatch >>> collections. >>> >>> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To post to this group, send email to sqlalchemy@googlegroups.com. >> To unsubscribe from this group, send email to >> sqlalchemy+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/sqlalchemy?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalchemy@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.