]> 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>
Thu, 10 Nov 2016 22:36:41 +0000 (17:36 -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.

(also trying different ways to get the changelog to merge cleanly)

Change-Id: Iaecdb4b3d8c3a3b44302a5880476e60a1f4e27d9
Fixes: #3778
doc/build/changelog/changelog_10.rst
lib/sqlalchemy/orm/mapper.py
test/orm/test_inspect.py

index bd419dfd719b76867d0ad71c38d5930b19afd632..532e86846032c890044125052ceca8a917ec01f5 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 87f2a24b022417e6a268900c511110faec1437e3..5156e432ce930b40a3d59441ce4348ea86844913 100644 (file)
@@ -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.
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')