]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed bug where in Py2K a unicode literal would not be accepted
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 29 Nov 2013 23:15:52 +0000 (18:15 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 29 Nov 2013 23:15:52 +0000 (18:15 -0500)
as the string name of a class or other argument within
declarative using :func:`.relationship`.

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

index a12b3f0dddbdc68d41b99ad589dc62ac2ca78de4..08b815a11f8e35a6ed843adf860cc6a876aa9cf6 100644 (file)
 .. changelog::
     :version: 0.9.0b2
 
+    .. change::
+        :tags: bug, orm, declarative
+
+        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:`.relationship`.
+
     .. change::
         :tags: feature, sql
         :tickets: 2877
index a669e37f46865236a6defaa9ff3966d0260aee40..8fef8f1bcb51461310f4c09647d4ff91f560163d 100644 (file)
@@ -277,7 +277,7 @@ def _deferred_relationship(cls, prop):
         for attr in ('argument', 'order_by', 'primaryjoin', 'secondaryjoin',
                      'secondary', '_user_defined_foreign_keys', 'remote_side'):
             v = getattr(prop, attr)
-            if isinstance(v, str):
+            if isinstance(v, util.string_types):
                 setattr(prop, attr, resolve_arg(v))
 
         if prop.backref and isinstance(prop.backref, tuple):
index 8917d77725fbee5287a19675c3e6c3520eeb7153..f5e7f2aa777a5c22d583e8abe36a6ac2c10f88fb 100644 (file)
@@ -4,7 +4,7 @@ from sqlalchemy.testing import eq_, assert_raises, \
 from sqlalchemy.ext import declarative as decl
 from sqlalchemy import exc
 import sqlalchemy as sa
-from sqlalchemy import testing
+from sqlalchemy import testing, util
 from sqlalchemy import MetaData, Integer, String, ForeignKey, \
     ForeignKeyConstraint, Index
 from sqlalchemy.testing.schema import Table, Column
@@ -77,6 +77,26 @@ class DeclarativeTest(DeclarativeTestBase):
         eq_(a1, Address(email='two'))
         eq_(a1.user, User(name='u1'))
 
+    def test_unicode_string_resolve(self):
+        class User(Base, fixtures.ComparableEntity):
+            __tablename__ = 'users'
+
+            id = Column('id', Integer, primary_key=True,
+                                        test_needs_autoincrement=True)
+            name = Column('name', String(50))
+            addresses = relationship(util.u("Address"), backref="user")
+
+        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')
+
+        assert User.addresses.property.mapper.class_ is Address
+
     def test_no_table(self):
         def go():
             class User(Base):