summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/build/changelog/changelog_09.rst6
-rw-r--r--lib/sqlalchemy/ext/associationproxy.py5
-rw-r--r--test/ext/test_associationproxy.py7
3 files changed, 16 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst
index e11710e61..1591872cd 100644
--- a/doc/build/changelog/changelog_09.rst
+++ b/doc/build/changelog/changelog_09.rst
@@ -15,6 +15,12 @@
: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 a4786de42..045645f86 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 487850601..6a4de0f74 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)