diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-03-14 15:01:17 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-03-14 15:01:17 -0400 |
| commit | a3c1774859eb80552bdf9beccd4160e246dfe014 (patch) | |
| tree | 3bba8fb4b2a14998b8d39213e5851917df5594d3 | |
| parent | d5d1e2df67048b77ef41626940189116ba98b2f0 (diff) | |
| download | sqlalchemy-a3c1774859eb80552bdf9beccd4160e246dfe014.tar.gz | |
- Arguments in __mapper_args__ that aren't "hashable"
aren't mistaken for always-hashable, possibly-column
arguments. [ticket:2091]
| -rw-r--r-- | CHANGES | 4 | ||||
| -rwxr-xr-x | lib/sqlalchemy/ext/declarative.py | 10 | ||||
| -rw-r--r-- | test/ext/test_declarative.py | 21 |
3 files changed, 31 insertions, 4 deletions
@@ -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 0372d4dac..e521ddbbf 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 12d347f28..27d53a990 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): |
