]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Arguments in __mapper_args__ that aren't "hashable"
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Mar 2011 19:01:17 +0000 (15:01 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Mar 2011 19:01:17 +0000 (15:01 -0400)
aren't mistaken for always-hashable, possibly-column
arguments.  [ticket:2091]

CHANGES
lib/sqlalchemy/ext/declarative.py
test/ext/test_declarative.py

diff --git a/CHANGES b/CHANGES
index 1a7212f874a2c99ff1b39f7d5e52956235670358..235c68113f19880b6304ca288b180fe0ca9887b7 100644 (file)
--- 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
index 0372d4daca75f911ba79fa0933a450f1464b8c31..e521ddbbf9e1187f049fe5d64dce43ba8a9e6cba 100755 (executable)
@@ -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, 
index 12d347f28a6827f7d396da65154568b86e2b9c46..27d53a9909e2b74ae57703a03346ccfa30281d81 100644 (file)
@@ -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):