"named" is not accepted for attribute events, engine events

Issue #3197 resolved
Mike Bayer repo owner created an issue
diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py
index c50a7b0..bd0b48f 100644
--- a/lib/sqlalchemy/orm/events.py
+++ b/lib/sqlalchemy/orm/events.py
@@ -1490,7 +1490,7 @@ class AttributeEvents(event.Events):
     @classmethod
     def _listen(cls, event_key, active_history=False,
                 raw=False, retval=False,
-                propagate=False):
+                propagate=False, **kw):

         target, identifier, fn = \
             event_key.dispatch_target, event_key.identifier, event_key.fn
@@ -1509,14 +1509,14 @@ class AttributeEvents(event.Events):
                     return fn(target, value, *arg)
             event_key = event_key.with_wrapper(wrap)

-        event_key.base_listen(propagate=propagate)
+        event_key.base_listen(propagate=propagate, **kw)

         if propagate:
             manager = instrumentation.manager_of_class(target.class_)

             for mgr in manager.subclass_managers(True):
                 event_key.with_dispatch_target(
-                    mgr[target.key]).base_listen(propagate=True)
+                    mgr[target.key]).base_listen(propagate=True, **kw)

     def append(self, target, value, initiator):
         """Receive a collection append event.
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import event

Base = declarative_base()

class A(Base):
    __tablename__ = 'a'

    id = Column(Integer, primary_key=True)
    bs = relationship("B")


class B(Base):
    __tablename__ = 'b'

    id = Column(Integer, primary_key=True)
    a_id = Column(Integer, ForeignKey('a.id'))

e = create_engine("sqlite://", echo=True)

sess = Session(e)


@event.listens_for(A.bs, 'set', named=True)
def update_challenge_points(target, **kw):
    pass

Comments (5)

  1. Mike Bayer reporter
    • Fixed bug that affected generally the same classes of event as that of 🎫3199, when the named=True parameter would be used. Some events would fail to register, and others would not invoke the event arguments correctly, generally in the case of when an event was "wrapped" for adaption in some other way. The "named" mechanics have been rearranged to not interfere with the argument signature expected by internal wrapper functions. fixes #3197

    → <<cset b36cdefba273>>

  2. Mike Bayer reporter
    • Fixed bug that affected generally the same classes of event as that of 🎫3199, when the named=True parameter would be used. Some events would fail to register, and others would not invoke the event arguments correctly, generally in the case of when an event was "wrapped" for adaption in some other way. The "named" mechanics have been rearranged to not interfere with the argument signature expected by internal wrapper functions. fixes #3197

    Conflicts: test/base/test_events.py test/orm/test_attributes.py test/orm/test_events.py

    → <<cset 912ebaa8b02f>>

  3. Log in to comment