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):
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):