]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added "post_configure_attribute" method to InstrumentationManager,
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 11 Feb 2009 18:23:35 +0000 (18:23 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 11 Feb 2009 18:23:35 +0000 (18:23 +0000)
so that the "listen_for_events.py" example works again.
[ticket:1314]

CHANGES
examples/custom_attributes/listen_for_events.py
lib/sqlalchemy/orm/attributes.py
lib/sqlalchemy/orm/interfaces.py

diff --git a/CHANGES b/CHANGES
index 95dfab4d57cab8b63dd982ad676916f3b8134d52..c2b32672ffe0d73a7c6bb7c95709095d9989ca52 100644 (file)
--- 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
index c028e0fb48220d530b3d4be12fc6f913f4fece73..de28df5b3a01e76244d45465c5cd83402c4a9893 100644 (file)
@@ -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.  
index 729ab12772838394ec17321e497c42877518c94f..657b961900c343693ee0ab403e870befc7c028a6 100644 (file)
@@ -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_)
 
index 7e5427808a9a832162aca46345b9adca3a264d16..3b7507def64cb96b0ec3c2253454eed606b00a72 100644 (file)
@@ -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)