From d6e8d5eddbca7154d008f7ef49efdc62dded7794 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 4 Mar 2014 10:59:27 -0500 Subject: [PATCH] - Fixed bug in association proxy where assigning an empty slice (e.g. ``x[:] = [...]``) would fail on Py3k. --- doc/build/changelog/changelog_09.rst | 6 ++++++ lib/sqlalchemy/ext/associationproxy.py | 5 +++-- test/ext/test_associationproxy.py | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) 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) -- 2.47.3