SelectResults has a little bug, the slices of slices are returning the
wrong results.
For example:
results = Person.mapper.select()
slice = results[10:20]
slice[5] should be equal to results[15], instead it's equal to results[5].
Included a patch with a couple of fixes and added the corresponding test
to test/selectresults.py (runs ok!).
--
Claudio
Index: lib/sqlalchemy/ext/selectresults.py
===================================================================
--- lib/sqlalchemy/ext/selectresults.py (revision 1466)
+++ lib/sqlalchemy/ext/selectresults.py (working copy)
@@ -66,11 +66,11 @@
else:
res = self.clone()
if start is not None and stop is not None:
- res._ops.update(dict(offset=start, limit=stop-start))
+ res._ops.update(dict(offset=self._ops.get('offset',
0)+start, limit=stop-start))
elif start is None and stop is not None:
res._ops.update(dict(limit=stop))
elif start is not None and stop is None:
- res._ops.update(dict(offset=start))
+ res._ops.update(dict(offset=self._ops.get('offset',
0)+start))
if item.step is not None:
return list(res)[None:None:item.step]
else:
Index: lib/sqlalchemy/mods/selectresults.py
===================================================================
--- lib/sqlalchemy/mods/selectresults.py (revision 1466)
+++ lib/sqlalchemy/mods/selectresults.py (working copy)
@@ -1,6 +1,7 @@
from sqlalchemy.ext.selectresults import *
+from sqlalchemy.orm.mapper import global_extensions
def install_plugin():
- orm.global_extensions.append(SelectResultsExt)
+ global_extensions.append(SelectResultsExt)
install_plugin()
Index: test/selectresults.py
===================================================================
--- test/selectresults.py (revision 1466)
+++ test/selectresults.py (working copy)
@@ -46,6 +46,7 @@
assert list(self.res[:10]) == self.orig[:10]
assert list(self.res[10:40:3]) == self.orig[10:40:3]
assert list(self.res[-5:]) == self.orig[-5:]
+ assert self.res[10:20][5] == self.orig[10:20][5]
def test_aggregate(self):
assert self.res.count() == 100