Merge lp:~rvb/storm/storm-0slice-bug-872086 into lp:storm

Proposed by Raphaël Badin
Status: Merged
Approved by: Thomas Herve
Approved revision: 416
Merged at revision: 417
Proposed branch: lp:~rvb/storm/storm-0slice-bug-872086
Merge into: lp:storm
Diff against target: 48 lines (+13/-3)
3 files modified
NEWS (+1/-0)
storm/sqlobject.py (+0/-3)
tests/sqlobject.py (+12/-0)
To merge this branch: bzr merge lp:~rvb/storm/storm-0slice-bug-872086
Reviewer Review Type Date Requested Status
Robert Collins (community) Needs Fixing
Thomas Herve (community) Approve
Gavin Panella Approve
Review via email: mp+79576@code.launchpad.net

Commit message

Fix how SQLObjectResultSet handles slicing when slice.start and slice.end are both zero.

Description of the change

This branch fixes how SQLObjectResultSet handles slicing when the start and the end of the slice are 0 (sqlobj[0:0]).

= Tests =

tests/sqlobject.py
- test_result_set_count_sliced_empty
- test_result_set_count_sliced_empty_zero

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) :
review: Approve
Revision history for this message
Thomas Herve (therve) wrote :

Looks good! please put a small note in the NEWS file and merge.

review: Approve
417. By Raphaël Badin

Add a note to NEWS.

Revision history for this message
Robert Collins (lifeless) wrote :

This is nearly right :) the if block you remove needs to stay and be tweaked though:
>>> range(10)[None:None]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

review: Needs Fixing
Revision history for this message
Raphaël Badin (rvb) wrote :

Without changing the code, this test passes:

    def test_result_set_count_sliced_none(self):
        result = self.Person.select()
        sliced_result = result[None:None]
        self.assertEquals(len(list(sliced_result)), 2)
        self.assertEquals(sliced_result.count(), 2)

I think the limit and offset parameters being None is a case that is already taken care of by the code (also, result[1:None] and result[None:4] behave as expected).

Revision history for this message
Robert Collins (lifeless) wrote :

Awesome! May be worth adding those tests if they aren't there already,
as future proofing.

Revision history for this message
Raphaël Badin (rvb) wrote :

Good point, I've added the tests.

Revision history for this message
Raphaël Badin (rvb) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2011-10-05 16:15:41 +0000
3+++ NEWS 2011-10-17 18:35:26 +0000
4@@ -7,6 +7,7 @@
5 Bug fixes
6 ---------
7
8+- When a SQLObjectResultSet object was sliced with slice.start and slice.end both zero (sqlobject[0:0]), the full, unsliced resultset was returned (bug #872086).
9
10 0.19 (2011-10-03)
11 =================
12
13=== modified file 'storm/sqlobject.py'
14--- storm/sqlobject.py 2011-04-13 03:20:36 +0000
15+++ storm/sqlobject.py 2011-10-17 18:35:26 +0000
16@@ -525,9 +525,6 @@
17
18 def __getitem__(self, index):
19 if isinstance(index, slice):
20- if not index.start and not index.stop:
21- return self
22-
23 if index.start and index.start < 0 or (
24 index.stop and index.stop < 0):
25 L = list(self)
26
27=== modified file 'tests/sqlobject.py'
28--- tests/sqlobject.py 2010-10-12 12:02:01 +0000
29+++ tests/sqlobject.py 2011-10-17 18:35:26 +0000
30@@ -755,6 +755,18 @@
31 self.assertEquals(len(list(sliced_result)), 1)
32 self.assertEquals(sliced_result.count(), 1)
33
34+ def test_result_set_count_sliced_empty(self):
35+ result = self.Person.select()
36+ sliced_result = result[1:1]
37+ self.assertEquals(len(list(sliced_result)), 0)
38+ self.assertEquals(sliced_result.count(), 0)
39+
40+ def test_result_set_count_sliced_empty_zero(self):
41+ result = self.Person.select()
42+ sliced_result = result[0:0]
43+ self.assertEquals(len(list(sliced_result)), 0)
44+ self.assertEquals(sliced_result.count(), 0)
45+
46 def test_result_set_count_distinct(self):
47 result = self.Person.select(
48 "person.id = phone.person_id",

Subscribers

People subscribed via source and target branches

to status/vote changes: