summaryrefslogtreecommitdiff
path: root/test/ext/test_mutable.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-01-28 13:48:05 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-01-28 13:48:05 -0500
commit029ae72b2fffc5a69acf7fc610377cd0a148870e (patch)
tree40cb58c19deeacfaf2c7f30507b0cafdf5066356 /test/ext/test_mutable.py
parent4480eea62225951263892831190012dcea10c2e0 (diff)
downloadsqlalchemy-029ae72b2fffc5a69acf7fc610377cd0a148870e.tar.gz
- [bug] Fixed bug where unpickled object didn't
have enough of its state set up to work correctly within the unpickle() event established by the mutable object extension, if the object needed ORM attribute access within __eq__() or similar. [ticket:2362]
Diffstat (limited to 'test/ext/test_mutable.py')
-rw-r--r--test/ext/test_mutable.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/test/ext/test_mutable.py b/test/ext/test_mutable.py
index 129a460b0..60576f007 100644
--- a/test/ext/test_mutable.py
+++ b/test/ext/test_mutable.py
@@ -17,6 +17,13 @@ class Foo(fixtures.BasicEntity):
class SubFoo(Foo):
pass
+class FooWithEq(object):
+ def __init__(self, **kw):
+ for k in kw:
+ setattr(self, k, kw[k])
+ def __eq__(self, other):
+ return self.id == other.id
+
class _MutableDictTestBase(object):
run_define_tables = 'each'
@@ -317,12 +324,10 @@ class _CompositeTestBase(object):
return self.x, self.y
def __getstate__(self):
- d = dict(self.__dict__)
- d.pop('_parents', None)
- return d
+ return self.x, self.y
- #def __setstate__(self, state):
- # self.x, self.y = state
+ def __setstate__(self, state):
+ self.x, self.y = state
def __eq__(self, other):
return isinstance(other, Point) and \
@@ -330,6 +335,23 @@ class _CompositeTestBase(object):
other.y == self.y
return Point
+class MutableCompositesUnpickleTest(_CompositeTestBase, fixtures.MappedTest):
+
+ @classmethod
+ def setup_mappers(cls):
+ foo = cls.tables.foo
+
+ cls.Point = cls._type_fixture()
+
+ mapper(FooWithEq, foo, properties={
+ 'data':composite(cls.Point, foo.c.x, foo.c.y)
+ })
+
+ def test_unpickle_modified_eq(self):
+ u1 = FooWithEq(data=self.Point(3, 5))
+ for loads, dumps in picklers():
+ loads(dumps(u1))
+
class MutableCompositesTest(_CompositeTestBase, fixtures.MappedTest):
@classmethod