Skip to content

Commit 4aa2496

Browse files
author
Guewen Baconnier
committed
Add job_serialized in IrModelFields.ttype selection
Context ------- The queue_job module adds a new type of field, with the type "job_serialized", which is close to the base "serialized" field, adding support of serialization for recordsets and a couple of common types such as datetime and date. This field type is used in several fields of the "queue.job" model. In the "ir.model.fields", each field is related to a "ttype", which is a selection containing every types of fields supported by the current database. The "job_serialized" field was never registered as a possible value for the ttype selection field. It seems it had never been an issue before Odoo 13.0. With Odoo 13.0, we may have this error on upgrades: INFO sample odoo.modules.loading: 297 modules loaded in 529.51s, 0 queries INFO sample odoo.addons.base.models.ir_model: Deleting 4@ir.model.fields.selection (base.selection__ir_model_fields__ttype__job_serialized) ERROR sample odoo.sql_db: bad query: UPDATE "ir_model_fields" SET "ttype"=NULL WHERE "ttype"='job_serialized' ERROR: null value in column "ttype" violates not-null constraint DETAIL: Failing row contains (4296, record_ids, null, queue.job, null, null, null, 266, Record, null, null, t, null, null, f, t, f, f, null, base, null, null, t, null, null, null, null, null, t, null, null, 1, 2020-08-11 13:03:09.913127, null, null). 2020-08-11 13:10:53,168 167 WARNING sample odoo.modules.loading: Transient module states were reset 2020-08-11 13:10:53,170 167 ERROR sample odoo.modules.registry: Failed to load registry Traceback (most recent call last): File "/odoo/src/odoo/modules/registry.py", line 86, in new odoo.modules.load_modules(registry._db, force_demo, status, update_module) File "/odoo/src/odoo/modules/loading.py", line 472, in load_modules env['ir.model.data']._process_end(processed_modules) File "/odoo/src/odoo/addons/base/models/ir_model.py", line 1990, in _process_end record.unlink() File "/odoo/src/odoo/addons/base/models/ir_model.py", line 1208, in unlink self.env.cr.execute(query, [selection.value]) File "/odoo/src/odoo/sql_db.py", line 168, in wrapper return f(self, *args, **kwargs) File "/odoo/src/odoo/sql_db.py", line 245, in execute res = self._obj.execute(query, params) psycopg2.IntegrityError: null value in column "ttype" violates not-null constraint DETAIL: Failing row contains (4296, record_ids, null, queue.job, null, null, null, 266, Record, null, null, t, null, null, f, t, f, f, null, base, null, null, t, null, null, null, null, null, t, null, null, 1, 2020-08-11 13:03:09.913127, null, null). Explanation ----------- In 13.0, a model "ir.model.fields.selection" storing the allowed selection for a field has been added (odoo/odoo@7593b88). When the "job_serialized" fields for queue_job are created, they are properly created in ir.model.fields with "job_serialized" as "ttype". It creates the entry in "ir.model.fields.selection". When we update the module, if it does not find "job_serialized" as a possible value for IrModelFields.ttype, it unlinks the entry in "ir.model.fields.selection". When this happens, an override of the "unlink()" method in "ir.model.fields.selection" force a NULL value in the selection fields (here IrModelFields.ttype). Fixes: #227
1 parent 0192c0d commit 4aa2496

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

queue_job/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from . import base
2+
from . import ir_model_fields
23
from . import queue_job
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2020 Camptocamp
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
3+
4+
from odoo import fields, models
5+
6+
7+
class IrModelFields(models.Model):
8+
_inherit = 'ir.model.fields'
9+
10+
ttype = fields.Selection(selection_add=[("job_serialized", "Job Serialized")])

0 commit comments

Comments
 (0)