]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Use configured props for mapper.attrs, mapper.all_orm_descriptors
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 10 Nov 2016 19:24:48 +0000 (14:24 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 11 Nov 2016 02:10:15 +0000 (21:10 -0500)
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.

Change-Id: Iaecdb4b3d8c3a3b44302a5880476e60a1f4e27d9
Fixes: #3778
(cherry picked from commit 6319eb0ce7c095ba7d4f60746ce12cf575730b46)

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/orm/mapper.py
test/orm/test_inspect.py

index d3dfbd91200370a4b8c06977c1cc67845682212c..85e4c8018c876c6a0215dee0d04bb6b1e5801155 100644 (file)
         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
index c1f8d28fdb4d2a1e42d7ecf50c991f989c39497a..6347f054a30d493eb6403d2cad9739e1b8b2762c 100644 (file)
@@ -2037,7 +2037,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.
@@ -2075,7 +2075,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.
index 4b69c2a712e316c10839e79a5803cbdc69f2c6f3..1d00fa3af445120212a6f044eb5daa9944af252c 100644 (file)
@@ -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')