From: Mike Bayer Date: Mon, 14 Mar 2011 19:01:17 +0000 (-0400) Subject: - Arguments in __mapper_args__ that aren't "hashable" X-Git-Tag: rel_0_7b3~26^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3c1774859eb80552bdf9beccd4160e246dfe014;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Arguments in __mapper_args__ that aren't "hashable" aren't mistaken for always-hashable, possibly-column arguments. [ticket:2091] --- diff --git a/CHANGES b/CHANGES index 1a7212f874..235c68113f 100644 --- a/CHANGES +++ b/CHANGES @@ -470,6 +470,10 @@ CHANGES - Fix error message referencing old @classproperty name to reference @declared_attr [ticket:2061] + - Arguments in __mapper_args__ that aren't "hashable" + aren't mistaken for always-hashable, possibly-column + arguments. [ticket:2091] + 0.6.6 ===== - orm diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 0372d4daca..e521ddbbf9 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -782,7 +782,7 @@ it as part of ``__table_args__``:: class MyMixin(object): a = Column(Integer) b = Column(Integer) - + @declared_attr def __table_args__(cls): return (Index('test_idx_%s' % cls.__tablename__, 'a', 'b'),) @@ -944,9 +944,10 @@ def _as_declarative(cls, classname, dict_): # make sure that column copies are used rather # than the original columns from any mixins - for k, v in mapper_args.iteritems(): - mapper_args[k] = column_copies.get(v,v) - + for k in ('version_id_col', 'polymorphic_on',): + if k in mapper_args: + v = mapper_args[k] + mapper_args[k] = column_copies.get(v,v) if classname in cls._decl_class_registry: util.warn("The classname %r is already in the registry of this" @@ -1122,6 +1123,7 @@ def _as_declarative(cls, classname, dict_): # change this ordering when we do [ticket:1892] our_stuff[k] = p.columns + [col] + cls.__mapper__ = mapper_cls(cls, table, properties=our_stuff, diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py index 12d347f28a..27d53a9909 100644 --- a/test/ext/test_declarative.py +++ b/test/ext/test_declarative.py @@ -1270,7 +1270,28 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): assert 'inherits' not in Person.__mapper_args__ assert class_mapper(Engineer).polymorphic_identity is None assert class_mapper(Engineer).polymorphic_on is Person.__table__.c.type + + def test_we_must_only_copy_column_mapper_args(self): + class Person(Base): + + __tablename__ = 'people' + id = Column(Integer, primary_key=True) + a=Column(Integer) + b=Column(Integer) + c=Column(Integer) + d=Column(Integer) + discriminator = Column('type', String(50)) + __mapper_args__ = {'polymorphic_on': discriminator, + 'polymorphic_identity': 'person', + 'version_id_col': 'a', + 'column_prefix': 'bar', + 'include_properties': ['id', 'a', 'b'], + } + assert class_mapper(Person).version_id_col == 'a' + assert class_mapper(Person).include_properties == set(['id', 'a', 'b']) + + def test_custom_join_condition(self): class Foo(Base):