summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-10-02 17:22:37 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-10-02 17:22:37 -0400
commitd9dc05adb689bc4eab2227a96af0d874696cc63d (patch)
tree3b855600dcead0f88e500086e5381f74be9b8da0 /lib/sqlalchemy/orm
parentd46985d699e6ebffe45c94d91cfa842271e06bb0 (diff)
downloadsqlalchemy-d9dc05adb689bc4eab2227a96af0d874696cc63d.tar.gz
- begin adding tests for event registration and dispatch standalone
- fix pickling again - other test fixes
Diffstat (limited to 'lib/sqlalchemy/orm')
-rw-r--r--lib/sqlalchemy/orm/events.py57
-rw-r--r--lib/sqlalchemy/orm/instrumentation.py2
-rw-r--r--lib/sqlalchemy/orm/state.py2
3 files changed, 43 insertions, 18 deletions
diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py
index 29274ac3b..ff9f7dbc6 100644
--- a/lib/sqlalchemy/orm/events.py
+++ b/lib/sqlalchemy/orm/events.py
@@ -20,9 +20,9 @@ class InstrumentationEvents(event.Events):
from sqlalchemy.orm.instrumentation import instrumentation_registry
if isinstance(target, type):
- return [instrumentation_registry]
+ return instrumentation_registry
else:
- return []
+ return None
@classmethod
def listen(cls, fn, identifier, target):
@@ -64,12 +64,12 @@ class InstanceEvents(event.Events):
from sqlalchemy.orm.instrumentation import ClassManager, manager_of_class
if isinstance(target, ClassManager):
- return [target]
+ return target
elif isinstance(target, type):
manager = manager_of_class(target)
if manager:
- return [manager]
- return []
+ return manager
+ return None
@classmethod
def listen(cls, fn, identifier, target, raw=False):
@@ -185,26 +185,51 @@ class AttributeEvents(event.Events):
def unwrap(cls, identifier, event):
return event['value']
- def on_append(self, state, value, initiator):
+ def on_append(self, target, value, initiator):
"""Receive a collection append event.
- The returned value will be used as the actual value to be
- appended.
+ :param target: the object instance receiving the event.
+ If the listener is registered with ``raw=True``, this will
+ be the :class:`.InstanceState` object.
+ :param value: the value being appended. If this listener
+ is registered with ``retval=True``, the listener
+ function must return this value, or a new value which
+ replaces it.
+ :param initiator: the attribute implementation object
+ which initiated this event.
"""
- def on_remove(self, state, value, initiator):
- """Receive a remove event.
+ def on_remove(self, target, value, initiator):
+ """Receive a collection remove event.
- No return value is defined.
+ :param target: the object instance receiving the event.
+ If the listener is registered with ``raw=True``, this will
+ be the :class:`.InstanceState` object.
+ :param value: the value being removed.
+ :param initiator: the attribute implementation object
+ which initiated this event.
"""
- def on_set(self, state, value, oldvalue, initiator):
- """Receive a set event.
-
- The returned value will be used as the actual value to be
- set.
+ def on_set(self, target, value, oldvalue, initiator):
+ """Receive a scalar set event.
+
+ :param target: the object instance receiving the event.
+ If the listener is registered with ``raw=True``, this will
+ be the :class:`.InstanceState` object.
+ :param value: the value being set. If this listener
+ is registered with ``retval=True``, the listener
+ function must return this value, or a new value which
+ replaces it.
+ :param oldvalue: the previous value being replaced. This
+ may also be the symbol ``NEVER_SET`` or ``NO_VALUE``.
+ If the listener is registered with ``active_history=True``,
+ the previous value of the attribute will be loaded from
+ the database if the existing value is currently unloaded
+ or expired.
+ :param initiator: the attribute implementation object
+ which initiated this event.
"""
diff --git a/lib/sqlalchemy/orm/instrumentation.py b/lib/sqlalchemy/orm/instrumentation.py
index 02ba5e1a2..52c1c7213 100644
--- a/lib/sqlalchemy/orm/instrumentation.py
+++ b/lib/sqlalchemy/orm/instrumentation.py
@@ -361,7 +361,7 @@ class _ClassInstrumentationAdapter(ClassManager):
self._adapted.instrument_attribute(self.class_, key, inst)
def post_configure_attribute(self, key):
- super(_ClassInstrumentationAdpter, self).post_configure_attribute(key)
+ super(_ClassInstrumentationAdapter, self).post_configure_attribute(key)
self._adapted.post_configure_attribute(self.class_, key, self[key])
def install_descriptor(self, key, inst):
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index 42fc5b98e..dc8a07c17 100644
--- a/lib/sqlalchemy/orm/state.py
+++ b/lib/sqlalchemy/orm/state.py
@@ -509,7 +509,7 @@ class MutableAttrInstanceState(InstanceState):
obj.__dict__.update(self.mutable_dict)
# re-establishes identity attributes from the key
- self.manager.dispatch.on_resurrect(self, obj)
+ self.manager.dispatch.on_resurrect(self)
return obj