]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed regression from 0.7.4 whereby
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 28 Jan 2012 15:45:23 +0000 (10:45 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 28 Jan 2012 15:45:23 +0000 (10:45 -0500)
using an already instrumented column from a
superclass as "polymorphic_on" failed to resolve
the underlying Column.  [ticket:2345]

CHANGES
lib/sqlalchemy/orm/mapper.py
test/ext/test_declarative.py

diff --git a/CHANGES b/CHANGES
index 7c3c6b9f7e0bd8308a4ec67d4b4264d98ffc8274..0c42b1f78374fe7a357ac78ffcacfdf9ea37e184 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -16,6 +16,11 @@ CHANGES
     restore_snapshot() is called a second time,
     discarding those changes. [ticket:2389]
 
+  - [bug] Fixed regression from 0.7.4 whereby
+    using an already instrumented column from a
+    superclass as "polymorphic_on" failed to resolve
+    the underlying Column.  [ticket:2345]
+
   - [feature] Added "class_registry" argument to
     declarative_base().  Allows two or more declarative
     bases to share the same registry of class names.
index 13b5b3e471ad77f09bf5fe9bc004fe465b2fb194..4c952c1fd5f8632c802fc47b7965282cf5a52bb5 100644 (file)
@@ -128,7 +128,7 @@ class Mapper(object):
         self.batch = batch
         self.eager_defaults = eager_defaults
         self.column_prefix = column_prefix
-        self.polymorphic_on = polymorphic_on
+        self.polymorphic_on = expression._clause_element_as_expr(polymorphic_on)
         self._dependency_processors = []
         self.validators = util.immutabledict()
         self.passive_updates = passive_updates
index 3069c2bfece364523981a978e1e2bc9bd57bb2eb..69042b5c84336ce95d10acee536b80e2b62b5878 100644 (file)
@@ -1,6 +1,6 @@
 
 from test.lib.testing import eq_, assert_raises, \
-    assert_raises_message
+    assert_raises_message, is_
 from sqlalchemy.ext import declarative as decl
 from sqlalchemy import exc
 import sqlalchemy as sa
@@ -1855,6 +1855,23 @@ class DeclarativeInheritanceTest(DeclarativeTestBase):
         eq_(sess.query(Engineer).filter_by(primary_language='cobol'
             ).one(), Engineer(name='vlad', primary_language='cobol'))
 
+    def test_polymorphic_on_converted_from_inst(self):
+        class A(Base):
+            __tablename__ = 'A'
+            id = Column(Integer, primary_key=True)
+            discriminator = Column(String)
+
+            @declared_attr
+            def __mapper_args__(cls):
+                return {
+                    'polymorphic_identity': cls.__name__,
+                    'polymorphic_on': cls.discriminator
+                }
+
+        class B(A):
+            pass
+        is_(B.__mapper__.polymorphic_on, A.__table__.c.discriminator)
+
     def test_add_deferred(self):
 
         class Person(Base, fixtures.ComparableEntity):