]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
py2k: accept unicode literals on :func:`backref`, too
authorNils Philippsen <nils@redhat.com>
Mon, 9 Nov 2015 13:50:23 +0000 (14:50 +0100)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 30 Nov 2015 17:49:12 +0000 (12:49 -0500)
Fixed bug where in Py2K a unicode literal would not be accepted as the
string name of a class or other argument within declarative using
:func:`.backref` on :func:`.relationship`.

amends commit e6f67f48054d906856f879bc1803ea639aa4b670

(cherry picked from commit 58f73d2278393d813c7f39736fc96c5086f18f6d)

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/ext/declarative/clsregistry.py
test/ext/declarative/test_basic.py

index b7b792d4d5a4d856ffa8fa95c7d0bba92c235d6d..f5e550ed0d494ad65e851817a1931d24efae2c00 100644 (file)
 .. changelog::
     :version: 1.0.10
 
+    .. change::
+        :tags: bug, orm
+        :pullreq: github:212
+        :versions: 1.1.0b1
+
+        Fixed bug where in Py2K a unicode literal would not be accepted as the
+        string name of a class or other argument within declarative using
+        :func:`.backref` on :func:`.relationship`.  Pull request courtesy
+        Nils Philippsen.
+
     .. change::
         :tags: bug, mssql
         :versions: 1.1.0b1
index c3887d6cf1cc0d09b56afe231a42a025bd659961..050923980f8ed22c87894fcaf0ebf4d4ebb15cfb 100644 (file)
@@ -321,7 +321,8 @@ def _deferred_relationship(cls, prop):
             key, kwargs = prop.backref
             for attr in ('primaryjoin', 'secondaryjoin', 'secondary',
                          'foreign_keys', 'remote_side', 'order_by'):
-                if attr in kwargs and isinstance(kwargs[attr], str):
+                if attr in kwargs and isinstance(kwargs[attr],
+                                                 util.string_types):
                     kwargs[attr] = resolve_arg(kwargs[attr])
 
     return prop
index ab0de801ce2340e54386738ac07973624b0d7bbd..b8e17debbd9b2f65b03a79d183aa0135328256cf 100644 (file)
@@ -102,6 +102,29 @@ class DeclarativeTest(DeclarativeTestBase):
 
         assert User.addresses.property.mapper.class_ is Address
 
+    def test_unicode_string_resolve_backref(self):
+        class User(Base, fixtures.ComparableEntity):
+            __tablename__ = 'users'
+
+            id = Column('id', Integer, primary_key=True,
+                        test_needs_autoincrement=True)
+            name = Column('name', String(50))
+
+        class Address(Base, fixtures.ComparableEntity):
+            __tablename__ = 'addresses'
+
+            id = Column(Integer, primary_key=True,
+                        test_needs_autoincrement=True)
+            email = Column(String(50), key='_email')
+            user_id = Column('user_id', Integer, ForeignKey('users.id'),
+                             key='_user_id')
+            user = relationship(
+                    User,
+                    backref=backref("addresses",
+                                    order_by=util.u("Address.email")))
+
+        assert Address.user.property.mapper.class_ is User
+
     def test_no_table(self):
         def go():
             class User(Base):