]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add a test for pullreq 8
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 23 Jun 2013 21:53:49 +0000 (17:53 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 23 Jun 2013 21:53:49 +0000 (17:53 -0400)
- simplify

lib/sqlalchemy/ext/mutable.py
test/ext/test_mutable.py

index 48c8d13cccf23fa8f1240935fe8bbad22e7c3c05..d3133b1f53df59fd86b5b3e4e6859ccf73b2b5e0 100644 (file)
@@ -588,11 +588,11 @@ class MutableComposite(MutableBase):
                 setattr(parent, attr_name, value)
 
 def _setup_composite_listener():
-    import types
     def _listen_for_type(mapper, class_):
         for prop in mapper.iterate_properties:
-            if (hasattr(prop, 'composite_class') and (type(prop.composite_class) in (types.ClassType, types.TypeType)) and
-                issubclass(prop.composite_class, MutableComposite)):
+            if (hasattr(prop, 'composite_class') and
+                isinstance(prop.composite_class, type) and
+                 issubclass(prop.composite_class, MutableComposite)):
                 prop.composite_class._listen_on_attribute(
                     getattr(class_, prop.key), False, class_)
     if not Mapper.dispatch.mapper_configured._contains(Mapper, _listen_for_type):
index bda9e5382e7ffa77ba57c236a34dc6ab56665959..25c182f1da45fd303d1a199fb4c21fe3d8c9cb8a 100644 (file)
@@ -421,6 +421,32 @@ class MutableCompositesTest(_CompositeTestBase, fixtures.MappedTest):
 
         eq_(f1.data.x, 5)
 
+class MutableCompositeCallableTest(_CompositeTestBase, fixtures.MappedTest):
+
+    @classmethod
+    def setup_mappers(cls):
+        foo = cls.tables.foo
+
+        Point = cls._type_fixture()
+
+        # in this case, this is not actually a MutableComposite.
+        # so we don't expect it to track changes
+        mapper(Foo, foo, properties={
+            'data': composite(lambda x, y: Point(x, y), foo.c.x, foo.c.y)
+        })
+
+    def test_basic(self):
+        sess = Session()
+        f1 = Foo(data=Point(3, 4))
+        sess.add(f1)
+        sess.flush()
+        f1.data.x = 5
+        sess.commit()
+
+        # we didn't get the change.
+        eq_(f1.data.x, 3)
+
+
 class MutableCompositeCustomCoerceTest(_CompositeTestBase, fixtures.MappedTest):
     @classmethod
     def _type_fixture(cls):