Merge lp:~therve/storm/resultset-select-copy into lp:storm

Proposed by Thomas Herve
Status: Merged
Merged at revision: 374
Proposed branch: lp:~therve/storm/resultset-select-copy
Merge into: lp:storm
Diff against target: 39 lines (+19/-0)
2 files modified
storm/store.py (+4/-0)
tests/store/base.py (+15/-0)
To merge this branch: bzr merge lp:~therve/storm/resultset-select-copy
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Approve
Jamu Kakar (community) Approve
Review via email: mp+34274@code.launchpad.net

Description of the change

The branches fixes copy by giving a real copy of the _select attribute, instead of a reference to the other ReferenceSet _select attribute.

To post a comment you must log in.
Revision history for this message
Jamu Kakar (jkakar) wrote :

Looks good to me, +1!

review: Approve
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Looks good to me as well. Just one detail if you don't mind:

[1]

Can you please add some docs right above the copying, pointing out the entanglement between the few pieces which create the bug, and which require the copying to happen? This will be very valuable in a week, when we don't recall what the heck this is about anymore. :-)

review: Approve
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Actually, the comment may be as simple as this:

"""
This expression must be copied because we may have to change it in-place inside _get_select().
"""

375. By Thomas Herve

Add a nice comment explaining why we copy the _select attribute.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storm/store.py'
2--- storm/store.py 2010-08-19 07:43:34 +0000
3+++ storm/store.py 2010-09-01 15:02:59 +0000
4@@ -927,6 +927,10 @@
5 """
6 result_set = object.__new__(self.__class__)
7 result_set.__dict__.update(self.__dict__)
8+ if self._select is not Undef:
9+ # This expression must be copied because we may have to change it
10+ # in-place inside _get_select().
11+ result_set._select = copy(self._select)
12 return result_set
13
14 def config(self, distinct=None, offset=None, limit=None):
15
16=== modified file 'tests/store/base.py'
17--- tests/store/base.py 2010-08-19 07:45:09 +0000
18+++ tests/store/base.py 2010-09-01 15:02:59 +0000
19@@ -940,6 +940,21 @@
20 def test_find_count(self):
21 self.assertEquals(self.store.find(Foo).count(), 3)
22
23+ def test_find_count_after_slice(self):
24+ """
25+ When we slice a ResultSet obtained after a set operation (like union),
26+ we get a fresh select that doesn't modify the limit and offset
27+ attribute of the original ResultSet.
28+ """
29+ result1 = self.store.find(Foo, Foo.id == 10)
30+ result2 = self.store.find(Foo, Foo.id == 20)
31+ result3 = result1.union(result2)
32+ result3.order_by(Foo.id)
33+ self.assertEquals(result3.count(), 2)
34+
35+ result_slice = list(result3[:2])
36+ self.assertEquals(result3.count(), 2)
37+
38 def test_find_count_column(self):
39 self.assertEquals(self.store.find(Link).count(Link.foo_id), 6)
40

Subscribers

People subscribed via source and target branches

to status/vote changes: