diff options
| author | Gilles Dartiguelongue <gilles.dartiguelongue@esiee.org> | 2014-12-09 12:08:12 +0100 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-03-10 14:28:50 -0400 |
| commit | 9fee9cb87e0d13db4426664f5758c1ddad0533e3 (patch) | |
| tree | 5c83504386746504d7fd38036dcbfb6d3fadb63f | |
| parent | 6ac0555eaa6363ac9d0ad6566248dd294ad61d9e (diff) | |
| download | sqlalchemy-9fee9cb87e0d13db4426664f5758c1ddad0533e3.tar.gz | |
Fix slice addressing of _AssociationList with python3
| -rw-r--r-- | lib/sqlalchemy/ext/associationproxy.py | 5 | ||||
| -rw-r--r-- | test/ext/test_associationproxy.py | 16 |
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index bb08ce9ba..c0e71068b 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -527,7 +527,10 @@ class _AssociationList(_AssociationCollection): return self.setter(object, value) def __getitem__(self, index): - return self._get(self.col[index]) + if not isinstance(index, slice): + return self._get(self.col[index]) + else: + return [self._get(member) for member in self.col[index]] def __setitem__(self, index, value): if not isinstance(index, slice): diff --git a/test/ext/test_associationproxy.py b/test/ext/test_associationproxy.py index 67e474705..9e328a35f 100644 --- a/test/ext/test_associationproxy.py +++ b/test/ext/test_associationproxy.py @@ -912,6 +912,22 @@ class LazyLoadTest(fixtures.TestBase): self.assert_('_children' in p.__dict__) self.assert_(len(p._children) == 3) + def test_slicing_list(self): + Parent, Child = self.Parent, self.Child + + mapper(Parent, self.table, properties={ + '_children': relationship(Child, lazy='select', + collection_class=list)}) + + p = Parent('p') + p.children = ['a', 'b', 'c'] + + p = self.roundtrip(p) + + self.assert_(len(p._children) == 3) + eq_('b', p.children[1]) + eq_(['b', 'c'], p.children[-2:]) + def test_lazy_scalar(self): Parent, Child = self.Parent, self.Child |
