]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed regression where we don't check the given name against the
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 2 Jan 2014 23:59:26 +0000 (18:59 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 2 Jan 2014 23:59:26 +0000 (18:59 -0500)
correct string class when setting up a backref based on a name,
therefore causing the error "too many values to unpack".  This was
related to the Py3k conversion. [ticket:2901]

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/orm/relationships.py
test/orm/test_mapper.py

index 783c674fd7d34dc29708970a3574a65dee2a2784..ae706fd837024a6dc8477fe721caf028cd120510 100644 (file)
 .. changelog::
     :version: 0.9.1
 
+    .. change::
+        :tags: bug, orm
+        :tickets: 2901
+
+        Fixed regression where we don't check the given name against the
+        correct string class when setting up a backref based on a name,
+        therefore causing the error "too many values to unpack".  This was
+        related to the Py3k conversion.
+
     .. change::
         :tags: bug, orm, declarative
         :tickets: 2900
index a4d1d43e3a94a2a384e035734a85fcd6f314d5a9..da402fbf345ffe57bcb7fca46d145ba654eef0f0 100644 (file)
@@ -1560,7 +1560,7 @@ class RelationshipProperty(StrategizedProperty):
         if not self.is_primary():
             return
         if self.backref is not None and not self.back_populates:
-            if isinstance(self.backref, str):
+            if isinstance(self.backref, util.string_types):
                 backref_key, kwargs = self.backref, {}
             else:
                 backref_key, kwargs = self.backref
index a3222bc8fd039cef17eb2bea8c1ff0528b241d62..4713bbc64b69bb52e79895bba7cb6e1d70df79bd 100644 (file)
@@ -303,6 +303,22 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL):
         })
         assert User.addresses.property is m.get_property('addresses')
 
+    def test_unicode_relationship_backref_names(self):
+        # test [ticket:2901]
+        users, Address, addresses, User = (self.tables.users,
+                                self.classes.Address,
+                                self.tables.addresses,
+                                self.classes.User)
+
+        mapper(Address, addresses)
+        mapper(User, users, properties={
+            util.u('addresses'): relationship(Address, backref=util.u('user'))
+        })
+        u1 = User()
+        a1 = Address()
+        u1.addresses.append(a1)
+        assert a1.user is u1
+
     def test_configure_on_prop_1(self):
         users, Address, addresses, User = (self.tables.users,
                                 self.classes.Address,