Skip to content

Commit

Permalink
[IMP] queue_job: use jsonb column for JobSerialized
Browse files Browse the repository at this point in the history
- Refactor the JobSerialized field on top of `odoo.fields.Json` to use jsonb column
- And be able to search jobs using the more advanced JSONB features
  • Loading branch information
QuocDuong1306 committed Sep 26, 2024
1 parent cfcceeb commit c4e6f82
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions queue_job/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from odoo.tools.func import lazy


class JobSerialized(fields.Field):
class JobSerialized(fields.Json):
"""Provide the storage for job fields stored as json
A base_type must be set, it must be dict, list or tuple.
Expand All @@ -23,7 +23,7 @@ class JobSerialized(fields.Field):
"""

type = "job_serialized"
column_type = ("text", "text")
_column_type = ('jsonb', 'jsonb')

_base_type = None

Expand Down Expand Up @@ -63,7 +63,10 @@ def convert_to_cache(self, value, record, validate=True):

def convert_to_record(self, value, record):
default = self._base_type_default_json(record.env)
return json.loads(value or default, cls=JobDecoder, env=record.env)
value = value or default
if not isinstance(value, (str | bytes | bytearray)):
value = json.dumps(value, cls=JobEncoder)
return json.loads(value, cls=JobDecoder, env=record.env)


class JobEncoder(json.JSONEncoder):
Expand Down

0 comments on commit c4e6f82

Please sign in to comment.