bulk update/delete events / invent new system for changing event arguments

Issue #2775 resolved
Mike Bayer repo owner created an issue

the bulk UD events should have access to the arguments that were passed:

def after_bulk_update(self, session, query, query_context, values, synchronize_session, result):
   ""

and while we're at it, mapper events should get some more context too:

    def before_insert(self, session, flush_context, mapper, connection, target):
         ""

how can we pull this off? we'd need to build a really smart argument adapter that uses inspect:

@event.legacy_signature("0.9", ["query", "query_context", "result"]("session",))
def after_bulk_update(self, session, query, query_context, values, synchronize_session, result):
   ""

legacy_signature would need to receive the decorated fn, use inspect to look at how many arguments it accepts, then produce a translation wrapper corresponding to the given signature. it should even stick a "..versionchanged::" directive into the docstring.

another issue, these events take a crapload of arguments. How do we deal with that? Let's support this too:

@event.listens_for(Session, "after_bulk_update")
def after_update(self, **kw):

with the above signature the event system will detect that, and just send all args in as key/value pairs, so that event handlers can be written more simply just to look for what they need.

Comments (2)

  1. Mike Bayer reporter

    02a81707dc8b7c4d69551cad195fb has the work within master for the moment. we might consider porting the documentation part of this to 0.8. before_insert() etc. is left alone. bulk update/delete, it's just sending the BulkUD object itself for now - I didn't want the **kw style to fire off implicitly, you need to listen with named=True to take advantage of that.

  2. Log in to comment