Event removal not working

Issue #2973 resolved
Konsta Vesterinen created an issue

Very simple test scenario:

import sqlalchemy as sa


@sa.event.listens_for(sa.orm.mapper, 'instrument_class')
def my_listener(mapper, cls):
    pass


sa.event.remove(
    sa.orm.mapper, 'instrument_class', my_listener
)

This throws a ValueError:

    def remove(self, event_key):
        target = event_key.dispatch_target
        stack = [target]
        while stack:
            cls = stack.pop(0)
            stack.extend(cls.__subclasses__())
            if cls in self._clslevel:
>               self._clslevel[cls].remove(event_key.fn)
E               ValueError: list.remove(x): x not in list

Maybe the event_key.fn should be event_key.fn_wrap instead?

Comments (3)

  1. Mike Bayer repo owner
    • Fixed bug where events set to listen at the class level (e.g. on the :class:.Mapper or :class:.ClassManager level, as opposed to on an individual mapped class, and also on :class:.Connection) that also made use of internal argument conversion (which is most within those categories) would fail to be removable. fixes #2973

    → <<cset e60529da7974>>

  2. Log in to comment