summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-09-10 14:14:50 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-09-10 14:14:50 -0400
commit14d2bb074cccdec32bd26a89353c30fd512b2aa2 (patch)
treeb8bea89172c620f0f015edd5359681e304a19ac6 /test
parent706d4fcc4f69b74a502be41f5eea3fedd9413bc7 (diff)
downloadsqlalchemy-14d2bb074cccdec32bd26a89353c30fd512b2aa2.tar.gz
- Fixed bug in ordering list where the order of items would be
thrown off during a collection replace event, if the reorder_on_append flag were set to True. The fix ensures that the ordering list only impacts the list that is explicitly associated with the object. fixes #3191
Diffstat (limited to 'test')
-rw-r--r--test/ext/test_orderinglist.py22
-rw-r--r--test/orm/test_collection.py17
2 files changed, 39 insertions, 0 deletions
diff --git a/test/ext/test_orderinglist.py b/test/ext/test_orderinglist.py
index 3223c8048..0eba137e7 100644
--- a/test/ext/test_orderinglist.py
+++ b/test/ext/test_orderinglist.py
@@ -349,6 +349,28 @@ class OrderingListTest(fixtures.TestBase):
self.assert_(srt.bullets[1].text == 'new 2')
self.assert_(srt.bullets[2].text == '3')
+ def test_replace_two(self):
+ """test #3191"""
+
+ self._setup(ordering_list('position', reorder_on_append=True))
+
+ s1 = Slide('Slide #1')
+
+ b1, b2, b3, b4 = Bullet('1'), Bullet('2'), Bullet('3'), Bullet('4')
+ s1.bullets = [b1, b2, b3]
+
+ eq_(
+ [b.position for b in s1.bullets],
+ [0, 1, 2]
+ )
+
+ s1.bullets = [b4, b2, b1]
+ eq_(
+ [b.position for b in s1.bullets],
+ [0, 1, 2]
+ )
+
+
def test_funky_ordering(self):
class Pos(object):
def __init__(self):
diff --git a/test/orm/test_collection.py b/test/orm/test_collection.py
index f94c742b3..82331b9af 100644
--- a/test/orm/test_collection.py
+++ b/test/orm/test_collection.py
@@ -2191,6 +2191,23 @@ class InstrumentationTest(fixtures.ORMTest):
f1.attr = l2
eq_(canary, [adapter_1, f1.attr._sa_adapter, None])
+ def test_referenced_by_owner(self):
+
+ class Foo(object):
+ pass
+
+ instrumentation.register_class(Foo)
+ attributes.register_attribute(
+ Foo, 'attr', uselist=True, useobject=True)
+
+ f1 = Foo()
+ f1.attr.append(3)
+
+ adapter = collections.collection_adapter(f1.attr)
+ assert adapter._referenced_by_owner
+
+ f1.attr = []
+ assert not adapter._referenced_by_owner