list of entities. In particular scalar subqueries
should not "leak" their inner FROM objects out
into the enclosing query.
+
+ - Fixed @on_reconsitute hook for subclasses
+ which inherit from a base class.
+ [ticket:1129]
- sql
- Temporarily rolled back the "ORDER BY" enhancement
from sqlalchemy.util import EMPTY_SET
from sqlalchemy.orm import interfaces, collections, exc
import sqlalchemy.exceptions as sa_exc
+import types
# lazy imports
_entity_info = None
self._instantiable = False
self.events = self.event_registry_factory()
- for meth in class_.__dict__.values():
- if hasattr(meth, '_sa_reconstitute'):
- self.events.add_listener('on_load', meth)
+ # TODO: generalize (and document the rationalization for) this traversal.
+ # TODO: figure out why getattr(cls, key) for all attributes
+ # causes test failures
+ for cls in class_.__mro__[0:-1]:
+ for key, meth in cls.__dict__.iteritems():
+ if isinstance(meth, types.FunctionType) and \
+ hasattr(meth, '__sa_reconstitute__') and \
+ hasattr(getattr(class_, key), '__sa_reconstitute__'):
+ self.events.add_listener('on_load', meth)
def instantiable(self, boolean):
# experiment, probably won't stay in this form
to MapperExtension.on_reconstitute().
"""
- fn._sa_reconstitute = True
+ fn.__sa_reconstitute__ = True
return fn
cls = object.__getattribute__(self, 'class_')
clskey = object.__getattribute__(self, 'key')
+ # ugly hack
if key.startswith('__') and key != '__clause_element__':
return object.__getattribute__(self, key)
s._run_on_load(m)
assert recon == ['go']
+ def test_inheritance(self):
+ recon = []
+ class MyBaseClass(object):
+ @attributes.on_reconstitute
+ def recon(self):
+ recon.append('go')
+
+ class MySubClass(MyBaseClass):
+ pass
+ attributes.register_class(MySubClass)
+ m = attributes.manager_of_class(MySubClass).new_instance()
+ s = attributes.instance_state(m)
+ s._run_on_load(m)
+ assert recon == ['go']
+
if __name__ == '__main__':
testing.main()