Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions queue_job/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class JobSerialized(fields.Json):
def __init__(self, string=SENTINEL, base_type=SENTINEL, **kwargs):
super().__init__(string=string, _base_type=base_type, **kwargs)

def _setup_attrs(self, model, name): # pylint: disable=missing-return
super()._setup_attrs(model, name)
def _setup_attrs__(self, model, name): # pylint: disable=missing-return
super()._setup_attrs__(model, name)
if self._base_type not in self._default_json_mapping:
msg = f"{self._base_type} is not a supported base type"
raise ValueError(msg)
Expand Down
8 changes: 7 additions & 1 deletion queue_job/tests/test_json_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# pylint: disable=odoo-addons-relative-import
# we are testing, we want to test as we were an external consumer of the API
from odoo.addons.queue_job.fields import JobDecoder, JobEncoder
from odoo.addons.queue_job.fields import JobDecoder, JobEncoder, JobSerialized


class TestJson(common.TransactionCase):
Expand Down Expand Up @@ -195,3 +195,9 @@ def test_decoder_etree(self):
value = json.loads(value_json, cls=JobDecoder, env=self.env)
value[2] = etree.tostring(value[2])
self.assertEqual(value, expected)

def test_job_serialized_base_type_is_validated(self):
model_class = type(self.env["queue.job"])
JobSerialized(base_type=dict)._setup_attrs__(model_class, "supported")
with self.assertRaisesRegex(ValueError, "is not a supported base type"):
JobSerialized(base_type=int)._setup_attrs__(model_class, "unsupported")
Loading