summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES4
-rw-r--r--examples/custom_attributes/listen_for_events.py3
-rw-r--r--lib/sqlalchemy/orm/attributes.py11
-rw-r--r--lib/sqlalchemy/orm/interfaces.py10
4 files changed, 23 insertions, 5 deletions
diff --git a/CHANGES b/CHANGES
index 95dfab4d5..c2b32672f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,10 @@ CHANGES
- When flushing partial sets of objects using session.flush([somelist]),
pending objects which remain pending after the operation won't
inadvertently be added as persistent. [ticket:1306]
+
+ - Added "post_configure_attribute" method to InstrumentationManager,
+ so that the "listen_for_events.py" example works again.
+ [ticket:1314]
- sql
- Fixed missing _label attribute on Function object, others
diff --git a/examples/custom_attributes/listen_for_events.py b/examples/custom_attributes/listen_for_events.py
index c028e0fb4..de28df5b3 100644
--- a/examples/custom_attributes/listen_for_events.py
+++ b/examples/custom_attributes/listen_for_events.py
@@ -7,11 +7,10 @@ across the board.
from sqlalchemy.orm.interfaces import AttributeExtension, InstrumentationManager
class InstallListeners(InstrumentationManager):
- def instrument_attribute(self, class_, key, inst):
+ def post_configure_attribute(self, class_, key, inst):
"""Add an event listener to an InstrumentedAttribute."""
inst.impl.extensions.insert(0, AttributeListener(key))
- return super(InstallListeners, self).instrument_attribute(class_, key, inst)
class AttributeListener(AttributeExtension):
"""Generic event listener.
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index 729ab1277..657b96190 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -1201,6 +1201,9 @@ class ClassManager(dict):
manager = create_manager_for_cls(cls)
manager.instrument_attribute(key, inst, True)
+ def post_configure_attribute(self, key):
+ pass
+
def uninstrument_attribute(self, key, propagated=False):
if key not in self:
return
@@ -1354,6 +1357,9 @@ class _ClassInstrumentationAdapter(ClassManager):
if not propagated:
self._adapted.instrument_attribute(self.class_, key, inst)
+ def post_configure_attribute(self, key):
+ self._adapted.post_configure_attribute(self.class_, key, self[key])
+
def install_descriptor(self, key, inst):
self._adapted.install_descriptor(self.class_, key, inst)
@@ -1579,9 +1585,10 @@ def register_attribute_impl(class_, key, **kw):
key, factory or list)
else:
typecallable = kw.pop('typecallable', None)
-
+
manager[key].impl = _create_prop(class_, key, manager, typecallable=typecallable, **kw)
-
+ manager.post_configure_attribute(key)
+
def register_descriptor(class_, key, proxy_property=None, comparator=None, parententity=None, property_=None):
manager = manager_of_class(class_)
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py
index 7e5427808..3b7507def 100644
--- a/lib/sqlalchemy/orm/interfaces.py
+++ b/lib/sqlalchemy/orm/interfaces.py
@@ -855,7 +855,12 @@ class LoaderStrategy(object):
return fn
class InstrumentationManager(object):
- """User-defined class instrumentation extension."""
+ """User-defined class instrumentation extension.
+
+ The API for this class should be considered as semi-stable,
+ and may change slightly with new releases.
+
+ """
# r4361 added a mandatory (cls) constructor to this interface.
# given that, perhaps class_ should be dropped from all of these
@@ -878,6 +883,9 @@ class InstrumentationManager(object):
def instrument_attribute(self, class_, key, inst):
pass
+ def post_configure_attribute(self, class_, key, inst):
+ pass
+
def install_descriptor(self, class_, key, inst):
setattr(class_, key, inst)