From: Mike Bayer Date: Thu, 10 Nov 2016 19:24:48 +0000 (-0500) Subject: Use configured props for mapper.attrs, mapper.all_orm_descriptors X-Git-Tag: rel_1_1_4~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2eb4aac9517a3775411c2ecf0f588ffd0d790f6;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Use configured props for mapper.attrs, mapper.all_orm_descriptors Fixed bug where the :attr:`.Mapper.attrs`, :attr:`.Mapper.all_orm_descriptors` and other derived attributes would fail to refresh when mapper properties or other ORM constructs were added to the mapper/class after these accessors were first called. (also trying different ways to get the changelog to merge cleanly) Change-Id: Iaecdb4b3d8c3a3b44302a5880476e60a1f4e27d9 Fixes: #3778 --- diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index bd419dfd71..532e868460 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -94,6 +94,17 @@ not function correctly in conjunction with a mapping that implements a version id counter. + .. 3778 + + .. change:: + :tickets: 3778 + :versions: 1.1.4 + + Fixed bug where the :attr:`.Mapper.attrs`, + :attr:`.Mapper.all_orm_descriptors` and other derived attributes would + fail to refresh when mapper properties or other ORM constructs were + added to the mapper/class after these accessors were first called. + .. changelog:: :version: 1.0.15 :released: September 1, 2016 diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 87f2a24b02..5156e432ce 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -2111,7 +2111,7 @@ class Mapper(InspectionAttr): continue yield c - @util.memoized_property + @_memoized_configured_property def attrs(self): """A namespace of all :class:`.MapperProperty` objects associated this mapper. @@ -2149,7 +2149,7 @@ class Mapper(InspectionAttr): configure_mappers() return util.ImmutableProperties(self._props) - @util.memoized_property + @_memoized_configured_property def all_orm_descriptors(self): """A namespace of all :class:`.InspectionAttr` attributes associated with the mapped class. diff --git a/test/orm/test_inspect.py b/test/orm/test_inspect.py index 4b69c2a712..1d00fa3af4 100644 --- a/test/orm/test_inspect.py +++ b/test/orm/test_inspect.py @@ -423,6 +423,34 @@ class TestORMInspection(_fixtures.FixtureTest): ) assert 'name' in u1.__dict__ + def test_attrs_props_prop_added_after_configure(self): + class AnonClass(object): + pass + + from sqlalchemy.orm import mapper, column_property + from sqlalchemy.ext.hybrid import hybrid_property + m = mapper(AnonClass, self.tables.users) + + eq_( + set(inspect(AnonClass).attrs.keys()), + set(['id', 'name'])) + eq_( + set(inspect(AnonClass).all_orm_descriptors.keys()), + set(['id', 'name'])) + + m.add_property('q', column_property(self.tables.users.c.name)) + + def desc(self): + return self.name + AnonClass.foob = hybrid_property(desc) + + eq_( + set(inspect(AnonClass).attrs.keys()), + set(['id', 'name', 'q'])) + eq_( + set(inspect(AnonClass).all_orm_descriptors.keys()), + set(['id', 'name', 'q', 'foob'])) + def test_instance_state_ident_transient(self): User = self.classes.User u1 = User(name='ed')