instrumentation events aren't specific to subclasses

Issue #2590 resolved
Mike Bayer repo owner created an issue

this is documented as the behavior of instrumentation events, so we should really get this right. probably we will need to wrap incoming events inside a filter for that subclass.

from sqlalchemy import Table, Column, MetaData, Integer
from sqlalchemy.orm import mapper, configure_mappers
from sqlalchemy import event

class Foo(object):
    pass

class Bar(object):
    pass

@event.listens_for(Foo, "attribute_instrument")
def nope(cls, key, inst):
    assert False

m = MetaData()
t = Table('t', m, Column('x', Integer, primary_key=True))

mapper(Bar, t)

configure_mappers()

Comments (5)

  1. Mike Bayer reporter

    also tricky. with #2585 those are class level events that ultimately we'd like them to become mapper-instance-level, though maybe not (what if class Foo is mapped, unmapped, remapped ? arg...) Then what if Foo is dereferenced ? a plain class-level mapper stays around forever.

    Perhaps the event system would have target-filters built in that make use of weak referencing.

  2. Mike Bayer reporter

    or another approach. as we receive unmapped, uninstrumented classes, we stick them in a weak map somewhere, then as new classes are instrumented and new mappers are created, we check against that collection to add new events. lets look into this as this is how attribute and mapper events work for subclasses right now.

  3. Log in to comment