diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-07-08 13:39:56 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-07-08 13:39:56 -0400 |
commit | 02a81707dc8b7c4d69551cad195fb16ca6955df1 (patch) | |
tree | feda05ad7e0ce7bef057b9ee9d55d3273d8d008a /lib/sqlalchemy/orm/events.py | |
parent | db68ecff12f790fd129f03b8676b317fa17e5f28 (diff) | |
download | sqlalchemy-02a81707dc8b7c4d69551cad195fb16ca6955df1.tar.gz |
- create a new system where we can decorate an event method
with @_legacy_signature, will inspect incoming listener functions
to see if they match an older signature, will wrap into a newer sig
- add an event listen argument named=True, will send all args as
kw args so that event listeners can be written with **kw, any combination
of names
- add a doc system to events that writes out the various calling styles
for a given event, produces deprecation messages automatically.
a little concerned that it's a bit verbose but will look at it up
on RTD for awhile to get a feel.
- change the calling signature for bulk update/delete events - we have
the BulkUD object right there, and there's at least six or seven things
people might want to see, so just send the whole BulkUD in
[ticket:2775]
Diffstat (limited to 'lib/sqlalchemy/orm/events.py')
-rw-r--r-- | lib/sqlalchemy/orm/events.py | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py index cea07bcf0..97019bb4e 100644 --- a/lib/sqlalchemy/orm/events.py +++ b/lib/sqlalchemy/orm/events.py @@ -42,6 +42,8 @@ class InstrumentationEvents(event.Events): """ + _target_class_doc = "SomeBaseClass" + @classmethod def _accept_with(cls, target): # TODO: there's no coverage for this @@ -151,6 +153,9 @@ class InstanceEvents(event.Events): object, rather than the mapped instance itself. """ + + _target_class_doc = "SomeMappedClass" + @classmethod def _accept_with(cls, target): if isinstance(target, orm.instrumentation.ClassManager): @@ -450,6 +455,8 @@ class MapperEvents(event.Events): """ + _target_class_doc = "SomeMappedClass" + @classmethod def _accept_with(cls, target): if target is orm.mapper: @@ -1083,6 +1090,9 @@ class SessionEvents(event.Events): globally. """ + + _target_class_doc = "SomeSessionOrFactory" + @classmethod def _accept_with(cls, target): if isinstance(target, orm.scoped_session): @@ -1382,31 +1392,55 @@ class SessionEvents(event.Events): """ - def after_bulk_update(self, session, query, query_context, result): + @event._legacy_signature("0.9", + ["session", "query", "query_context", "result"], + lambda update_context: ( + update_context.session, + update_context.query, + update_context.context, + update_context.result)) + def after_bulk_update(self, update_context): """Execute after a bulk update operation to the session. This is called as a result of the :meth:`.Query.update` method. - :param query: the :class:`.Query` object that this update operation was - called upon. - :param query_context: The :class:`.QueryContext` object, corresponding - to the invocation of an ORM query. - :param result: the :class:`.ResultProxy` returned as a result of the - bulk UPDATE operation. + :param update_context: an "update context" object which contains + details about the update, including these attributes: + + * ``session`` - the :class:`.Session` involved + * ``query`` -the :class:`.Query` object that this update operation was + called upon. + * ``context`` The :class:`.QueryContext` object, corresponding + to the invocation of an ORM query. + * ``result`` the :class:`.ResultProxy` returned as a result of the + bulk UPDATE operation. + """ - def after_bulk_delete(self, session, query, query_context, result): + @event._legacy_signature("0.9", + ["session", "query", "query_context", "result"], + lambda delete_context: ( + delete_context.session, + delete_context.query, + delete_context.context, + delete_context.result)) + def after_bulk_delete(self, delete_context): """Execute after a bulk delete operation to the session. This is called as a result of the :meth:`.Query.delete` method. - :param query: the :class:`.Query` object that this update operation was - called upon. - :param query_context: The :class:`.QueryContext` object, corresponding - to the invocation of an ORM query. - :param result: the :class:`.ResultProxy` returned as a result of the - bulk DELETE operation. + :param delete_context: a "delete context" object which contains + details about the update, including these attributes: + + * ``session`` - the :class:`.Session` involved + * ``query`` -the :class:`.Query` object that this update operation was + called upon. + * ``context`` The :class:`.QueryContext` object, corresponding + to the invocation of an ORM query. + * ``result`` the :class:`.ResultProxy` returned as a result of the + bulk DELETE operation. + """ @@ -1468,6 +1502,8 @@ class AttributeEvents(event.Events): """ + _target_class_doc = "SomeClass.some_attribute" + @classmethod def _accept_with(cls, target): # TODO: coverage |