From: Mike Bayer Date: Fri, 29 Nov 2013 23:15:52 +0000 (-0500) Subject: Fixed bug where in Py2K a unicode literal would not be accepted X-Git-Tag: rel_0_9_0~79 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e6f67f48054d906856f879bc1803ea639aa4b670;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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`. --- diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index a12b3f0ddd..08b815a11f 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -14,6 +14,13 @@ .. 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 diff --git a/lib/sqlalchemy/ext/declarative/clsregistry.py b/lib/sqlalchemy/ext/declarative/clsregistry.py index a669e37f46..8fef8f1bcb 100644 --- a/lib/sqlalchemy/ext/declarative/clsregistry.py +++ b/lib/sqlalchemy/ext/declarative/clsregistry.py @@ -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): diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py index 8917d77725..f5e7f2aa77 100644 --- a/test/ext/declarative/test_basic.py +++ b/test/ext/declarative/test_basic.py @@ -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):