Merge lp:~allenap/launchpad/series-init-failure-explanations-bug-835024-db into lp:launchpad

Proposed by Gavin Panella on 2011-09-13
Status: Merged
Approved by: Gavin Panella on 2011-09-13
Approved revision: no longer in the source branch.
Merged at revision: 13954
Proposed branch: lp:~allenap/launchpad/series-init-failure-explanations-bug-835024-db
Merge into: lp:launchpad
Diff against target: 208 lines (+17/-39)
6 files modified
lib/lp/services/memcache/restful.py (+2/-4)
lib/lp/soyuz/model/distributionjob.py (+3/-13)
lib/lp/soyuz/model/distroseriesdifferencejob.py (+5/-5)
lib/lp/soyuz/model/initializedistroseriesjob.py (+1/-3)
lib/lp/soyuz/model/packagecopyjob.py (+5/-13)
versions.cfg (+1/-1)
To merge this branch: bzr merge lp:~allenap/launchpad/series-init-failure-explanations-bug-835024-db
Reviewer Review Type Date Requested Status
Graham Binns (community) code 2011-09-13 Approve on 2011-09-13
Review via email: mp+75183@code.launchpad.net

Commit message

[r=gmb][bug=835024] Use the new JSON property in DistributionJob.

Description of the change

This switches DistributionJob to using the new JSON property from Storm.

To post a comment you must log in.
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/services/memcache/restful.py'
2--- lib/lp/services/memcache/restful.py 2010-08-20 20:31:18 +0000
3+++ lib/lp/services/memcache/restful.py 2011-09-13 13:46:24 +0000
4@@ -4,11 +4,9 @@
5 """Storm/memcached implementation of lazr.restful's representation cache."""
6
7 from lazr.restful.simple import BaseRepresentationCache
8-from lazr.restful.utils import get_current_web_service_request
9 import storm
10 from zope.component import getUtility
11 from zope.security.proxy import removeSecurityProxy
12-from zope.traversing.browser import absoluteURL
13
14 from canonical.config import config
15 from lp.services.memcache.interfaces import IMemcacheClient
16@@ -32,11 +30,11 @@
17 obj = removeSecurityProxy(obj)
18 try:
19 storm_info = storm.info.get_obj_info(obj)
20- except storm.exceptions.ClassInfoError, e:
21+ except storm.exceptions.ClassInfoError:
22 # There's no Storm data for this object. Don't cache it,
23 # since we don't know how to invalidate the cache.
24 return self.DO_NOT_CACHE
25- table_name = storm_info.cls_info.table
26+ table_name = storm_info.cls_info.table.name
27 primary_key = tuple(var.get() for var in storm_info.primary_vars)
28 identifier = table_name + repr(primary_key)
29
30
31=== modified file 'lib/lp/soyuz/model/distributionjob.py'
32--- lib/lp/soyuz/model/distributionjob.py 2011-09-09 19:23:39 +0000
33+++ lib/lp/soyuz/model/distributionjob.py 2011-09-13 13:46:24 +0000
34@@ -9,12 +9,11 @@
35 ]
36
37 from lazr.delegates import delegates
38-import simplejson
39 from storm.locals import (
40 And,
41 Int,
42+ JSON,
43 Reference,
44- Unicode,
45 )
46 from zope.interface import implements
47
48@@ -52,7 +51,7 @@
49
50 job_type = EnumCol(enum=DistributionJobType, notNull=True)
51
52- _json_data = Unicode('json_data')
53+ metadata = JSON('json_data')
54
55 def __init__(self, distribution, distroseries, job_type, metadata):
56 super(DistributionJob, self).__init__()
57@@ -60,16 +59,7 @@
58 self.distribution = distribution
59 self.distroseries = distroseries
60 self.job_type = job_type
61- self._json_data = self.serializeMetadata(metadata)
62-
63- @classmethod
64- def serializeMetadata(cls, metadata_dict):
65- """Serialize a dict of metadata into a unicode string."""
66- return simplejson.dumps(metadata_dict).decode('utf-8')
67-
68- @property
69- def metadata(self):
70- return simplejson.loads(self._json_data)
71+ self.metadata = metadata
72
73
74 class DistributionJobDerived(BaseRunnableJob):
75
76=== modified file 'lib/lp/soyuz/model/distroseriesdifferencejob.py'
77--- lib/lp/soyuz/model/distroseriesdifferencejob.py 2011-08-31 14:05:59 +0000
78+++ lib/lp/soyuz/model/distroseriesdifferencejob.py 2011-09-13 13:46:24 +0000
79@@ -8,6 +8,7 @@
80 'DistroSeriesDifferenceJob',
81 ]
82
83+import simplejson
84 from zope.component import getUtility
85 from zope.interface import (
86 classProvides,
87@@ -84,8 +85,8 @@
88 :return: A tuple of: derived distribution id, derived distroseries id,
89 job type, job id, JSON data map.
90 """
91- json = DistributionJob.serializeMetadata(make_metadata(
92- sourcepackagename_id, parent_series.id))
93+ json = simplejson.dumps(
94+ make_metadata(sourcepackagename_id, parent_series.id))
95 return (
96 derived_series.distribution.id,
97 derived_series.id,
98@@ -141,8 +142,7 @@
99 # the metadata string. It's fragile, but this is only an
100 # optimization. It's not actually disastrous to create
101 # redundant jobs occasionally.
102- json_metadata = DistributionJob.serializeMetadata(
103- make_metadata(sourcepackagename.id, parent_series.id))
104+ json_metadata = make_metadata(sourcepackagename.id, parent_series.id)
105
106 # Use master store because we don't like outdated information
107 # here.
108@@ -153,7 +153,7 @@
109 DistributionJob.job_type ==
110 DistributionJobType.DISTROSERIESDIFFERENCE,
111 DistributionJob.distroseries == derived_series,
112- DistributionJob._json_data == json_metadata,
113+ DistributionJob.metadata == json_metadata,
114 DistributionJob.job_id.is_in(Job.ready_jobs))
115
116 return [
117
118=== modified file 'lib/lp/soyuz/model/initializedistroseriesjob.py'
119--- lib/lp/soyuz/model/initializedistroseriesjob.py 2011-09-09 19:23:39 +0000
120+++ lib/lp/soyuz/model/initializedistroseriesjob.py 2011-09-13 13:46:24 +0000
121@@ -7,7 +7,6 @@
122 "InitializeDistroSeriesJob",
123 ]
124
125-import simplejson
126 from zope.interface import (
127 classProvides,
128 implements,
129@@ -206,8 +205,7 @@
130 # This method is called when error is an instance of
131 # self.user_error_types.
132 super(InitializeDistroSeriesJob, self).notifyUserError(error)
133- metadata = dict(self.metadata, error_description=unicode(error))
134- self.context._json_data = simplejson.dumps(metadata).decode("utf-8")
135+ self.metadata = dict(self.metadata, error_description=unicode(error))
136
137 def getOopsVars(self):
138 """See `IRunnableJob`."""
139
140=== modified file 'lib/lp/soyuz/model/packagecopyjob.py'
141--- lib/lp/soyuz/model/packagecopyjob.py 2011-08-23 14:35:43 +0000
142+++ lib/lp/soyuz/model/packagecopyjob.py 2011-09-13 13:46:24 +0000
143@@ -15,6 +15,7 @@
144 from storm.locals import (
145 And,
146 Int,
147+ JSON,
148 Reference,
149 Unicode,
150 )
151@@ -103,7 +104,7 @@
152
153 job_type = EnumCol(enum=PackageCopyJobType, notNull=True)
154
155- _json_data = Unicode('json_data')
156+ metadata = JSON('json_data')
157
158 # Derived concrete classes. The entire class gets one dict for
159 # this; it's not meant to be on an instance.
160@@ -145,16 +146,7 @@
161 self.target_distroseries = target_distroseries
162 self.package_name = unicode(package_name)
163 self.copy_policy = copy_policy
164- self._json_data = self.serializeMetadata(metadata)
165-
166- @classmethod
167- def serializeMetadata(cls, metadata_dict):
168- """Serialize a dict of metadata into a unicode string."""
169- return simplejson.dumps(metadata_dict).decode('utf-8')
170-
171- @property
172- def metadata(self):
173- return simplejson.loads(self._json_data)
174+ self.metadata = metadata
175
176 @property
177 def package_version(self):
178@@ -164,7 +156,7 @@
179 """Add metadata_dict to the existing metadata."""
180 existing = self.metadata
181 existing.update(metadata_dict)
182- self._json_data = self.serializeMetadata(existing)
183+ self.metadata = existing
184
185 @property
186 def component_name(self):
187@@ -294,7 +286,7 @@
188 data = (
189 cls.class_job_type, target_distroseries, copy_policy,
190 source_archive, target_archive, package_name, job_id,
191- PackageCopyJob.serializeMetadata(metadata))
192+ simplejson.dumps(metadata, ensure_ascii=False))
193 format_string = "(%s)" % ", ".join(["%s"] * len(data))
194 return format_string % sqlvalues(*data)
195
196
197=== modified file 'versions.cfg'
198--- versions.cfg 2011-09-12 23:52:19 +0000
199+++ versions.cfg 2011-09-13 13:46:24 +0000
200@@ -85,7 +85,7 @@
201 soupmatchers = 0.1r53
202 sourcecodegen = 0.6.9
203 # lp:~launchpad-committers/storm/with-without-datetime
204-storm = 0.18.0.99-lpwithnodatetime-r396
205+storm = 0.18.0.99-lpwithnodatetime-r398
206 testresources = 0.2.4-r58
207 testtools = 0.9.12-r228
208 timeline = 0.0.1