]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- additional fix for [ticket:2750] where on an update, we make sure the
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 30 Jun 2013 19:58:50 +0000 (15:58 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 30 Jun 2013 19:59:26 +0000 (15:59 -0400)
value is present

lib/sqlalchemy/orm/mapper.py
test/orm/inheritance/test_basic.py

index 5d35d1ca84c4125c835d7304e04ca094fe5aa03a..ff235eaf08665116b6d81a2fb91156eabe78a86c 100644 (file)
@@ -1052,7 +1052,8 @@ class Mapper(_InspectionAttr):
                         state.manager.mapper.polymorphic_identity, None)
 
             def _validate_polymorphic_identity(mapper, state, dict_):
-                if dict_[polymorphic_key] not in \
+                if polymorphic_key in dict_ and \
+                    dict_[polymorphic_key] not in \
                     mapper._acceptable_polymorphic_identities:
                     util.warn(
                                 "Flushing object %s with "
index 14d43e0c790b55b5ebb33a47ae981283ae2ccc21..0ac17db89f017219c4e7ddc0e79184a4c09f9649 100644 (file)
@@ -555,11 +555,12 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest):
         Table('table_b', metadata,
            Column('id', Integer, ForeignKey('table_a.id'),
                                 primary_key=True),
-           Column('class_name', String(50))
+           Column('class_name', String(50)),
         )
         Table('table_c', metadata,
            Column('id', Integer, ForeignKey('table_b.id'),
-                                primary_key=True)
+                                primary_key=True),
+           Column('data', String(10))
         )
 
     @classmethod
@@ -684,6 +685,36 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest):
             sess.flush
         )
 
+    def test_not_set_on_upate(self):
+        C = self.classes.C
+
+        sess = Session()
+        c1 = C()
+        sess.add(c1)
+        sess.commit()
+        sess.expire(c1)
+
+        c1.data = 'foo'
+        sess.flush()
+
+    def test_validate_on_upate(self):
+        C = self.classes.C
+
+        sess = Session()
+        c1 = C()
+        sess.add(c1)
+        sess.commit()
+        sess.expire(c1)
+
+        c1.class_name = 'b'
+        assert_raises_message(
+            sa_exc.SAWarning,
+            "Flushing object %s with incompatible "
+            "polymorphic identity 'b'; the object may not "
+            "refresh and/or load correctly" % instance_str(c1),
+            sess.flush
+        )
+
 class CascadeTest(fixtures.MappedTest):
     """that cascades on polymorphic relationships continue
     cascading along the path of the instance's mapper, not