]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- :func:`.composite` will raise an informative error message when the
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 12 Dec 2013 18:30:16 +0000 (13:30 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 12 Dec 2013 18:30:16 +0000 (13:30 -0500)
columns/attribute (names) passed don't resolve to a Column or mapped
attribute (such as an erroneous tuple); previously raised an unbound
local. [ticket:2889]

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/orm/descriptor_props.py
test/orm/test_composites.py

index 2cd9b58554fae78938395f36d49c528f711d0022..2e1bdc9ad67e9ba447c57d0fd5e43325a5e8c354 100644 (file)
 .. changelog::
     :version: 0.8.5
 
+    .. change::
+        :tags: bug, orm
+        :versions: 0.9.0b2
+        :tickets: 2889
+
+        :func:`.composite` will raise an informative error message when the
+        columns/attribute (names) passed don't resolve to a Column or mapped
+        attribute (such as an erroneous tuple); previously raised an unbound
+        local.
+
     .. change::
         :tags: bug, declarative
         :versions: 0.9.0b2
index 1156a140e98a30c381cb52c2f0ac3ee29523435e..231e531e43643e1e91346bc25820764d4575998c 100644 (file)
@@ -245,6 +245,11 @@ class CompositeProperty(DescriptorProperty):
                 prop = self.parent._columntoproperty[attr]
             elif isinstance(attr, attributes.InstrumentedAttribute):
                 prop = attr.property
+            else:
+                raise sa_exc.ArgumentError(
+                        "Composite expects Column or Column-bound "
+                        "attributes/attribute names as arguments, got: %r"
+                        % (attr,))
             props.append(prop)
 
     @property
index b4abb2dcee96618ad472eeb2cacb596523f5dabe..8946b6908d032fbd50517e8ccac263231f6d5b5c 100644 (file)
@@ -6,7 +6,7 @@ from sqlalchemy import Integer, String, ForeignKey, \
 from sqlalchemy.testing.schema import Table, Column
 from sqlalchemy.orm import mapper, relationship, \
     CompositeProperty, aliased
-from sqlalchemy.orm import composite, Session
+from sqlalchemy.orm import composite, Session, configure_mappers
 from sqlalchemy.testing import eq_
 from sqlalchemy.testing import fixtures
 
@@ -739,6 +739,24 @@ class ConfigurationTest(fixtures.MappedTest):
         })
         self._test_roundtrip()
 
+    def test_check_prop_type(self):
+        edge, Edge, Point = (self.tables.edge,
+                                self.classes.Edge,
+                                self.classes.Point)
+        mapper(Edge, edge, properties={
+            'start': sa.orm.composite(Point, (edge.c.x1,), edge.c.y1),
+        })
+        assert_raises_message(
+            sa.exc.ArgumentError,
+            # note that we also are checking that the tuple
+            # renders here, so the "%" operator in the string needs to
+            # apply the tuple also
+            r"Composite expects Column or Column-bound "
+            "attributes/attribute names as "
+            "arguments, got: \(Column",
+            configure_mappers
+        )
+
 class ComparatorTest(fixtures.MappedTest, testing.AssertsCompiledSQL):
     __dialect__ = 'default'