From: Mike Bayer Date: Tue, 4 Mar 2014 15:59:27 +0000 (-0500) Subject: - Fixed bug in association proxy where assigning an empty slice X-Git-Tag: rel_0_9_4~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6e8d5eddbca7154d008f7ef49efdc62dded7794;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug in association proxy where assigning an empty slice (e.g. ``x[:] = [...]``) would fail on Py3k. --- diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index e11710e61b..1591872cdf 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -14,6 +14,12 @@ .. changelog:: :version: 0.9.4 + .. change:: + :tags: bug, ext, py3k + + Fixed bug in association proxy where assigning an empty slice + (e.g. ``x[:] = [...]``) would fail on Py3k. + .. change:: :tags: bug, general :tickets: 2979 diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index a4786de42d..045645f866 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -540,11 +540,12 @@ class _AssociationList(_AssociationCollection): stop = index.stop step = index.step or 1 + start = index.start or 0 rng = list(range(index.start or 0, stop, step)) if step == 1: for i in rng: - del self[index.start] - i = index.start + del self[start] + i = start for item in value: self.insert(i, item) i += 1 diff --git a/test/ext/test_associationproxy.py b/test/ext/test_associationproxy.py index 4878506019..6a4de0f746 100644 --- a/test/ext/test_associationproxy.py +++ b/test/ext/test_associationproxy.py @@ -212,6 +212,13 @@ class _CollectionOperations(fixtures.TestBase): self.assert_(p1.children == after) self.assert_([c.name for c in p1._children] == after) + p1.children[:] = ['d', 'e'] + after = ['d', 'e'] + self.assert_(p1.children == after) + self.assert_([c.name for c in p1._children] == after) + + p1.children[:] = ['a', 'b'] + p1.children += ['c'] after = ['a', 'b', 'c'] self.assert_(p1.children == after)