launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24534
[Merge] ~cjwatson/launchpad:py3-job-json-text into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-job-json-text into launchpad:master.
Commit message:
Fix coercing of JSON data to text in job models
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/381341
This approach works on both Python 2 and 3.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-job-json-text into launchpad:master.
diff --git a/lib/lp/answers/model/questionjob.py b/lib/lp/answers/model/questionjob.py
index 1e73e5a..8b47fff 100644
--- a/lib/lp/answers/model/questionjob.py
+++ b/lib/lp/answers/model/questionjob.py
@@ -10,6 +10,7 @@ __all__ = [
from lazr.delegates import delegate_to
import simplejson
+import six
from storm.expr import And
from storm.locals import (
Int,
@@ -81,7 +82,7 @@ class QuestionJob(StormBase):
self.job_type = job_type
self.question = question
json_data = simplejson.dumps(metadata)
- self._json_data = json_data.decode('utf-8')
+ self._json_data = six.ensure_text(json_data)
def __repr__(self):
return (
diff --git a/lib/lp/bugs/model/apportjob.py b/lib/lp/bugs/model/apportjob.py
index da21da7..c91c6ec 100644
--- a/lib/lp/bugs/model/apportjob.py
+++ b/lib/lp/bugs/model/apportjob.py
@@ -13,6 +13,7 @@ from cStringIO import StringIO
from lazr.delegates import delegate_to
import simplejson
+import six
from sqlobject import SQLObjectNotFound
from storm.expr import And
from storm.locals import (
@@ -73,7 +74,7 @@ class ApportJob(StormBase):
# only delegates to ApportJob we can't simply directly access the
# _json_data property, so we use a getter and setter here instead.
def _set_metadata(self, metadata):
- self._json_data = unicode(
+ self._json_data = six.ensure_text(
simplejson.dumps(metadata, 'utf-8'))
def _get_metadata(self):
@@ -96,7 +97,7 @@ class ApportJob(StormBase):
self.job_type = job_type
# XXX AaronBentley 2009-01-29 bug=322819: This should be a
# bytestring, but the DB representation is unicode.
- self._json_data = json_data.decode('utf-8')
+ self._json_data = six.ensure_text(json_data)
@classmethod
def get(cls, key):
diff --git a/lib/lp/code/model/branchmergeproposaljob.py b/lib/lp/code/model/branchmergeproposaljob.py
index d6cd0ec..bd9fbef 100644
--- a/lib/lp/code/model/branchmergeproposaljob.py
+++ b/lib/lp/code/model/branchmergeproposaljob.py
@@ -37,6 +37,7 @@ from lazr.enum import (
)
import pytz
import simplejson
+import six
from sqlobject import SQLObjectNotFound
from storm.expr import (
And,
@@ -186,7 +187,7 @@ class BranchMergeProposalJob(StormBase):
self.job_type = job_type
# XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring,
# but the DB representation is unicode.
- self._json_data = json_data.decode('utf-8')
+ self._json_data = six.ensure_text(json_data)
def sync(self):
store = Store.of(self)
diff --git a/lib/lp/registry/model/persontransferjob.py b/lib/lp/registry/model/persontransferjob.py
index 4ed90de..426adf1 100644
--- a/lib/lp/registry/model/persontransferjob.py
+++ b/lib/lp/registry/model/persontransferjob.py
@@ -14,6 +14,7 @@ from datetime import datetime
from lazr.delegates import delegate_to
import pytz
import simplejson
+import six
from storm.expr import (
And,
Or,
@@ -121,7 +122,7 @@ class PersonTransferJob(StormBase):
json_data = simplejson.dumps(metadata)
# XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring,
# but the DB representation is unicode.
- self._json_data = json_data.decode('utf-8')
+ self._json_data = six.ensure_text(json_data)
def makeDerived(self):
return PersonTransferJobDerived.makeSubclass(self)
diff --git a/lib/lp/registry/model/productjob.py b/lib/lp/registry/model/productjob.py
index 20c83f0..4213786 100644
--- a/lib/lp/registry/model/productjob.py
+++ b/lib/lp/registry/model/productjob.py
@@ -20,6 +20,7 @@ from datetime import (
from lazr.delegates import delegate_to
from pytz import utc
import simplejson
+import six
from storm.expr import (
And,
Not,
@@ -156,7 +157,7 @@ class ProductJob(StormBase):
self.product = product
self.job_type = job_type
json_data = simplejson.dumps(metadata)
- self._json_data = json_data.decode('utf-8')
+ self._json_data = six.ensure_text(json_data)
@delegate_to(IProductJob)
diff --git a/lib/lp/registry/model/sharingjob.py b/lib/lp/registry/model/sharingjob.py
index a3dd532..9d2c444 100644
--- a/lib/lp/registry/model/sharingjob.py
+++ b/lib/lp/registry/model/sharingjob.py
@@ -18,6 +18,7 @@ from lazr.enum import (
DBItem,
)
import simplejson
+import six
from sqlobject import SQLObjectNotFound
from storm.expr import (
And,
@@ -160,7 +161,7 @@ class SharingJob(StormBase):
self.distro = pillar
# XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring,
# but the DB representation is unicode.
- self._json_data = json_data.decode('utf-8')
+ self._json_data = six.ensure_text(json_data)
def destroySelf(self):
Store.of(self).remove(self)