]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed bug where list instrumentation would fail to represent a
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 20 Aug 2013 17:27:27 +0000 (13:27 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 20 Aug 2013 17:29:14 +0000 (13:29 -0400)
setslice of ``[0:0]`` correctly, which in particular could occur
when using ``insert(0, item)`` with the association proxy.  Due
to some quirk in Python collections, the issue was much more likely
with Python 3 rather than 2.  Also in 0.8.3, 0.7.11.
[ticket:2807]

Conflicts:
doc/build/changelog/changelog_09.rst

Conflicts:
doc/build/changelog/changelog_08.rst

doc/build/changelog/changelog_07.rst
lib/sqlalchemy/orm/collections.py
test/orm/test_collection.py

index 738e8974639d43824548af37e1e687d3dfa3f753..d7d3019d2ea8568d10109ad302cb155b0bd100f9 100644 (file)
@@ -6,6 +6,16 @@
 .. changelog::
     :version: 0.7.11
 
+    .. change::
+        :tags: bug, orm
+        :tickets: 2807
+
+        Fixed bug where list instrumentation would fail to represent a
+        setslice of ``[0:0]`` correctly, which in particular could occur
+        when using ``insert(0, item)`` with the association proxy.  Due
+        to some quirk in Python collections, the issue was much more likely
+        with Python 3 rather than 2.
+
     .. change::
         :tags: bug, sql
         :tickets: 2801
index e26a59731f2a0ee3f9a81a500729e6a2cad4c1af..bb2d272c4cc1f8d4b07120b43bd2b53ce7d91883 100644 (file)
@@ -1078,7 +1078,10 @@ def _list_decorators():
                 start = index.start or 0
                 if start < 0:
                     start += len(self)
-                stop = index.stop or len(self)
+                if index.stop is not None:
+                    stop = index.stop
+                else:
+                    stop = len(self)
                 if stop < 0:
                     stop += len(self)
 
index b3de03aaef61506d9f1a8020d13e6a8a2d320d48..0f54da5517bfc76ec05ca2038cfe2c3e4df33870 100644 (file)
@@ -127,9 +127,9 @@ class CollectionsTest(fixtures.ORMTest):
         control = list()
 
         def assert_eq():
-            self.assert_(set(direct) == canary.data)
-            self.assert_(set(adapter) == canary.data)
-            self.assert_(direct == control)
+            eq_(set(direct), canary.data)
+            eq_(set(adapter), canary.data)
+            eq_(direct, control)
 
         # assume append() is available for list tests
         e = creator()
@@ -259,6 +259,11 @@ class CollectionsTest(fixtures.ORMTest):
             control[-2:-1] = values
             assert_eq()
 
+            values = [creator()]
+            direct[0:0] = values
+            control[0:0] = values
+            assert_eq()
+
 
         if hasattr(direct, '__delitem__') or hasattr(direct, '__delslice__'):
             for i in range(1, 4):