From: Mike Bayer Date: Wed, 11 Feb 2009 18:23:35 +0000 (+0000) Subject: - Added "post_configure_attribute" method to InstrumentationManager, X-Git-Tag: rel_0_5_3~35 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=60dd7842f012c7aaaa534ce22be06b0db25d86df;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Added "post_configure_attribute" method to InstrumentationManager, so that the "listen_for_events.py" example works again. [ticket:1314] --- diff --git a/CHANGES b/CHANGES index 95dfab4d57..c2b32672ff 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 c028e0fb48..de28df5b3a 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 729ab12772..657b961900 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 7e5427808a..3b7507def6 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)