]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- The :meth:`.InspectionAttr.info` collection is now moved down to
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 13 Aug 2014 23:20:44 +0000 (19:20 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 13 Aug 2014 23:20:44 +0000 (19:20 -0400)
:class:`.InspectionAttr`, where in addition to being available
on all :class:`.MapperProperty` objects, it is also now available
on hybrid properties, association proxies, when accessed via
:attr:`.Mapper.all_orm_descriptors`.
fixes #2971

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/orm/base.py
lib/sqlalchemy/orm/interfaces.py
test/ext/test_hybrid.py

index 20023af44d8727f199209ef6deb06f38c6c561c3..c59d7c912d9cbfcd6e97c9c88d19beb5715cf422 100644 (file)
 .. changelog::
        :version: 1.0.0
 
+    .. change::
+        :tags: orm, feature
+        :tickets: 2971
+
+        The :meth:`.InspectionAttr.info` collection is now moved down to
+        :class:`.InspectionAttr`, where in addition to being available
+        on all :class:`.MapperProperty` objects, it is also now available
+        on hybrid properties, association proxies, when accessed via
+        :attr:`.Mapper.all_orm_descriptors`.
+
     .. change::
         :tags: sql, feature
         :tickets: 3027
index 3097b8590f6da26d2996b1531dc7dda57d76ac4f..3390ceec4c21dfe978a7fe0e82ceddc914126d47 100644 (file)
@@ -488,6 +488,32 @@ class InspectionAttr(object):
 
     """
 
+    @util.memoized_property
+    def info(self):
+        """Info dictionary associated with the object, allowing user-defined
+        data to be associated with this :class:`.InspectionAttr`.
+
+        The dictionary is generated when first accessed.  Alternatively,
+        it can be specified as a constructor argument to the
+        :func:`.column_property`, :func:`.relationship`, or :func:`.composite`
+        functions.
+
+        .. versionadded:: 0.8  Added support for .info to all
+           :class:`.MapperProperty` subclasses.
+
+        .. versionchanged:: 1.0.0 :attr:`.InspectionAttr.info` moved
+           from :class:`.MapperProperty` so that it can apply to a wider
+           variety of ORM and extension constructs.
+
+        .. seealso::
+
+            :attr:`.QueryableAttribute.info`
+
+            :attr:`.SchemaItem.info`
+
+        """
+        return {}
+
 
 class _MappedAttribute(object):
     """Mixin for attributes which should be replaced by mapper-assigned
index 2dfaf62430571b15421fedae436b6cafd9bf8f5c..49ec99ce450cd6f790b6ed776e185eb5c773bb97 100644 (file)
@@ -109,28 +109,6 @@ class MapperProperty(_MappedAttribute, InspectionAttr):
     def instrument_class(self, mapper):  # pragma: no-coverage
         raise NotImplementedError()
 
-    @util.memoized_property
-    def info(self):
-        """Info dictionary associated with the object, allowing user-defined
-        data to be associated with this :class:`.MapperProperty`.
-
-        The dictionary is generated when first accessed.  Alternatively,
-        it can be specified as a constructor argument to the
-        :func:`.column_property`, :func:`.relationship`, or :func:`.composite`
-        functions.
-
-        .. versionadded:: 0.8  Added support for .info to all
-           :class:`.MapperProperty` subclasses.
-
-        .. seealso::
-
-            :attr:`.QueryableAttribute.info`
-
-            :attr:`.SchemaItem.info`
-
-        """
-        return {}
-
     _configure_started = False
     _configure_finished = False
 
index e7f392a3388fd9e6c55828f871008cc43e0a1f30..b895d2fb2b59049f25aeeb0132274d4e8cbd4792 100644 (file)
@@ -5,6 +5,7 @@ from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.ext import hybrid
 from sqlalchemy.testing import eq_, AssertsCompiledSQL, assert_raises_message
 from sqlalchemy.testing import fixtures
+from sqlalchemy import inspect
 
 class PropertyComparatorTest(fixtures.TestBase, AssertsCompiledSQL):
     __dialect__ = 'default'
@@ -140,6 +141,14 @@ class PropertyExpressionTest(fixtures.TestBase, AssertsCompiledSQL):
 
         return A, B
 
+    def test_info(self):
+        A = self._fixture()
+        inspect(A).all_orm_descriptors.value.info["some key"] = "some value"
+        eq_(
+            inspect(A).all_orm_descriptors.value.info,
+            {"some key": "some value"}
+        )
+
     def test_set_get(self):
         A = self._fixture()
         a1 = A(value=5)
@@ -267,6 +276,15 @@ class MethodExpressionTest(fixtures.TestBase, AssertsCompiledSQL):
             "foo(a.value, :foo_1) + :foo_2"
         )
 
+    def test_info(self):
+        A = self._fixture()
+        inspect(A).all_orm_descriptors.value.info["some key"] = "some value"
+        eq_(
+            inspect(A).all_orm_descriptors.value.info,
+            {"some key": "some value"}
+        )
+
+
     def test_aliased_expression(self):
         A = self._fixture()
         self.assert_compile(