Merge lp:~jamesh/storm/bug-136806 into lp:storm

Proposed by James Henstridge
Status: Merged
Approved by: Jamu Kakar
Approved revision: 286
Merged at revision: not available
Proposed branch: lp:~jamesh/storm/bug-136806
Merge into: lp:storm
Diff against target: 115 lines
To merge this branch: bzr merge lp:~jamesh/storm/bug-136806
Reviewer Review Type Date Requested Status
Jamu Kakar (community) Approve
Thomas Herve (community) Approve
Review via email: mp+1925@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Henstridge (jamesh) wrote :

ListVariable.get(to_db=True) did not correctly handle converting its items into Variable objects. This bug was masked by the test using a type with the same representation on the Python and database sides (an integer).

I've switched the test to use a use a list of enumeration variables to highlight the problem (as reported in bug 136806), and fixed the underlying problem.

lp:~jamesh/storm/bug-136806 updated
285. By James Henstridge

Add a test to show that lists of enumerations are handled correctly at
the store level.

Revision history for this message
Thomas Herve (therve) wrote :

Great, +1.

review: Approve
lp:~jamesh/storm/bug-136806 updated
286. By James Henstridge

merge from trunk, fixing conflicts

Revision history for this message
Jamu Kakar (jkakar) wrote :

+1!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storm/variables.py'
2--- storm/variables.py 2009-02-25 08:40:31 +0000
3+++ storm/variables.py 2009-03-04 17:20:14 +0000
4@@ -622,8 +622,7 @@
5 def parse_get(self, value, to_db):
6 if to_db:
7 item_factory = self._item_factory
8- # XXX This from_db=to_db is dubious. What to do here?
9- return [item_factory(value=val, from_db=to_db) for val in value]
10+ return [item_factory(value=val, from_db=False) for val in value]
11 else:
12 return value
13
14
15=== modified file 'tests/store/postgres.py'
16--- tests/store/postgres.py 2009-02-25 08:40:31 +0000
17+++ tests/store/postgres.py 2009-03-04 17:20:14 +0000
18@@ -22,7 +22,7 @@
19 import gc
20
21 from storm.database import create_database
22-from storm.properties import Int, List
23+from storm.properties import Enum, Int, List
24 from storm.info import get_obj_info
25
26 from tests.store.base import StoreTest, EmptyResultSetTest, Foo
27@@ -34,6 +34,11 @@
28 id = Int(primary=True)
29 ints = List(type=Int())
30
31+class LstEnum(object):
32+ __storm_table__ = "lst1"
33+ id = Int(primary=True)
34+ ints = List(type=Enum(map={"one": 1, "two": 2, "three": 3}))
35+
36 class Lst2(object):
37 __storm_table__ = "lst2"
38 id = Int(primary=True)
39@@ -119,6 +124,27 @@
40 result = self.store.execute("SELECT ints FROM lst1 WHERE id=1")
41 self.assertEquals(result.get_one(), ([1,2,3,4,5],))
42
43+ def test_list_enum_variable(self):
44+
45+ lst = LstEnum()
46+ lst.id = 1
47+ lst.ints = ["one", "two"]
48+ self.store.add(lst)
49+
50+ result = self.store.execute("SELECT ints FROM lst1 WHERE id=1")
51+ self.assertEquals(result.get_one(), ([1,2],))
52+
53+ del lst
54+ gc.collect()
55+
56+ lst = self.store.find(LstEnum, LstEnum.ints == ["one", "two"]).one()
57+ self.assertTrue(lst)
58+
59+ lst.ints.append("three")
60+
61+ result = self.store.execute("SELECT ints FROM lst1 WHERE id=1")
62+ self.assertEquals(result.get_one(), ([1,2,3],))
63+
64 def test_list_variable_nested(self):
65
66 lst = Lst2()
67
68=== modified file 'tests/variables.py'
69--- tests/variables.py 2009-02-20 01:54:08 +0000
70+++ tests/variables.py 2009-03-04 17:20:14 +0000
71@@ -887,20 +887,26 @@
72 class ListVariableTest(TestHelper):
73
74 def test_get_set(self):
75- l = [1, 2]
76+ # Enumeration variables are used as items so that database
77+ # side and python side values can be distinguished.
78+ get_map = {1: "a", 2: "b", 3: "c"}
79+ set_map = {"a": 1, "b": 2, "c": 3}
80+ item_factory = VariableFactory(
81+ EnumVariable, get_map=get_map, set_map=set_map)
82+
83+ l = ["a", "b"]
84 l_dump = pickle.dumps(l, -1)
85+ l_vars = [item_factory(value=x) for x in l]
86
87- variable = ListVariable(IntVariable)
88+ variable = ListVariable(item_factory)
89
90 variable.set(l)
91 self.assertEquals(variable.get(), l)
92- self.assertVariablesEqual(variable.get(to_db=True),
93- [IntVariable(1), IntVariable(2)])
94+ self.assertVariablesEqual(variable.get(to_db=True), l_vars)
95
96- variable.set([1.1, 2.2], from_db=True)
97+ variable.set([1, 2], from_db=True)
98 self.assertEquals(variable.get(), l)
99- self.assertVariablesEqual(variable.get(to_db=True),
100- [IntVariable(1), IntVariable(2)])
101+ self.assertVariablesEqual(variable.get(to_db=True), l_vars)
102
103 self.assertEquals(variable.get_state(), (Undef, l_dump))
104
105@@ -908,8 +914,8 @@
106 variable.set_state((Undef, l_dump))
107 self.assertEquals(variable.get(), l)
108
109- variable.get().append(3)
110- self.assertEquals(variable.get(), [1, 2, 3])
111+ variable.get().append("c")
112+ self.assertEquals(variable.get(), ["a", "b", "c"])
113
114 def test_list_events(self):
115 event = EventSystem(marker)

Subscribers

People subscribed via source and target branches

to status/vote changes: