Merge ~cjwatson/launchpad:py3-job-json-text into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 381c8e93e3254315a0cd520f7443f10ac032968e
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-job-json-text
Merge into: launchpad:master
Diff against target: 135 lines (+13/-7)
6 files modified
lib/lp/answers/model/questionjob.py (+2/-1)
lib/lp/bugs/model/apportjob.py (+3/-2)
lib/lp/code/model/branchmergeproposaljob.py (+2/-1)
lib/lp/registry/model/persontransferjob.py (+2/-1)
lib/lp/registry/model/productjob.py (+2/-1)
lib/lp/registry/model/sharingjob.py (+2/-1)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+381341@code.launchpad.net

Commit message

Fix coercing of JSON data to text in job models

Description of the change

This approach works on both Python 2 and 3.

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/answers/model/questionjob.py b/lib/lp/answers/model/questionjob.py
2index 1e73e5a..8b47fff 100644
3--- a/lib/lp/answers/model/questionjob.py
4+++ b/lib/lp/answers/model/questionjob.py
5@@ -10,6 +10,7 @@ __all__ = [
6
7 from lazr.delegates import delegate_to
8 import simplejson
9+import six
10 from storm.expr import And
11 from storm.locals import (
12 Int,
13@@ -81,7 +82,7 @@ class QuestionJob(StormBase):
14 self.job_type = job_type
15 self.question = question
16 json_data = simplejson.dumps(metadata)
17- self._json_data = json_data.decode('utf-8')
18+ self._json_data = six.ensure_text(json_data)
19
20 def __repr__(self):
21 return (
22diff --git a/lib/lp/bugs/model/apportjob.py b/lib/lp/bugs/model/apportjob.py
23index da21da7..c91c6ec 100644
24--- a/lib/lp/bugs/model/apportjob.py
25+++ b/lib/lp/bugs/model/apportjob.py
26@@ -13,6 +13,7 @@ from cStringIO import StringIO
27
28 from lazr.delegates import delegate_to
29 import simplejson
30+import six
31 from sqlobject import SQLObjectNotFound
32 from storm.expr import And
33 from storm.locals import (
34@@ -73,7 +74,7 @@ class ApportJob(StormBase):
35 # only delegates to ApportJob we can't simply directly access the
36 # _json_data property, so we use a getter and setter here instead.
37 def _set_metadata(self, metadata):
38- self._json_data = unicode(
39+ self._json_data = six.ensure_text(
40 simplejson.dumps(metadata, 'utf-8'))
41
42 def _get_metadata(self):
43@@ -96,7 +97,7 @@ class ApportJob(StormBase):
44 self.job_type = job_type
45 # XXX AaronBentley 2009-01-29 bug=322819: This should be a
46 # bytestring, but the DB representation is unicode.
47- self._json_data = json_data.decode('utf-8')
48+ self._json_data = six.ensure_text(json_data)
49
50 @classmethod
51 def get(cls, key):
52diff --git a/lib/lp/code/model/branchmergeproposaljob.py b/lib/lp/code/model/branchmergeproposaljob.py
53index d6cd0ec..bd9fbef 100644
54--- a/lib/lp/code/model/branchmergeproposaljob.py
55+++ b/lib/lp/code/model/branchmergeproposaljob.py
56@@ -37,6 +37,7 @@ from lazr.enum import (
57 )
58 import pytz
59 import simplejson
60+import six
61 from sqlobject import SQLObjectNotFound
62 from storm.expr import (
63 And,
64@@ -186,7 +187,7 @@ class BranchMergeProposalJob(StormBase):
65 self.job_type = job_type
66 # XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring,
67 # but the DB representation is unicode.
68- self._json_data = json_data.decode('utf-8')
69+ self._json_data = six.ensure_text(json_data)
70
71 def sync(self):
72 store = Store.of(self)
73diff --git a/lib/lp/registry/model/persontransferjob.py b/lib/lp/registry/model/persontransferjob.py
74index 4ed90de..426adf1 100644
75--- a/lib/lp/registry/model/persontransferjob.py
76+++ b/lib/lp/registry/model/persontransferjob.py
77@@ -14,6 +14,7 @@ from datetime import datetime
78 from lazr.delegates import delegate_to
79 import pytz
80 import simplejson
81+import six
82 from storm.expr import (
83 And,
84 Or,
85@@ -121,7 +122,7 @@ class PersonTransferJob(StormBase):
86 json_data = simplejson.dumps(metadata)
87 # XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring,
88 # but the DB representation is unicode.
89- self._json_data = json_data.decode('utf-8')
90+ self._json_data = six.ensure_text(json_data)
91
92 def makeDerived(self):
93 return PersonTransferJobDerived.makeSubclass(self)
94diff --git a/lib/lp/registry/model/productjob.py b/lib/lp/registry/model/productjob.py
95index 20c83f0..4213786 100644
96--- a/lib/lp/registry/model/productjob.py
97+++ b/lib/lp/registry/model/productjob.py
98@@ -20,6 +20,7 @@ from datetime import (
99 from lazr.delegates import delegate_to
100 from pytz import utc
101 import simplejson
102+import six
103 from storm.expr import (
104 And,
105 Not,
106@@ -156,7 +157,7 @@ class ProductJob(StormBase):
107 self.product = product
108 self.job_type = job_type
109 json_data = simplejson.dumps(metadata)
110- self._json_data = json_data.decode('utf-8')
111+ self._json_data = six.ensure_text(json_data)
112
113
114 @delegate_to(IProductJob)
115diff --git a/lib/lp/registry/model/sharingjob.py b/lib/lp/registry/model/sharingjob.py
116index a3dd532..9d2c444 100644
117--- a/lib/lp/registry/model/sharingjob.py
118+++ b/lib/lp/registry/model/sharingjob.py
119@@ -18,6 +18,7 @@ from lazr.enum import (
120 DBItem,
121 )
122 import simplejson
123+import six
124 from sqlobject import SQLObjectNotFound
125 from storm.expr import (
126 And,
127@@ -160,7 +161,7 @@ class SharingJob(StormBase):
128 self.distro = pillar
129 # XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring,
130 # but the DB representation is unicode.
131- self._json_data = json_data.decode('utf-8')
132+ self._json_data = six.ensure_text(json_data)
133
134 def destroySelf(self):
135 Store.of(self).remove(self)

Subscribers

People subscribed via source and target branches

to status/vote changes: