[REM] base: remove _sequence attribute of BaseModel

The `_sequence` was only used for the insertion of data in the DB for
the `id` value. But in Odoo, the `id` is always a `SERIAL`, then the
PostgreSQL fill already the value by the right SQL sequence. Then,
avoid doing the job of the DB by ourselves.
Sadly, we need to manage the case when we create an empty record to
always get a valid query.

task-2735546

Part-of: odoo/odoo#82727
This commit is contained in:
Rémy Voet (ryv)
2022-02-01 10:54:18 +00:00
committed by Raphael Collet
parent e44f866853
commit 6000179384
4 changed files with 5 additions and 12 deletions
-5
View File
@@ -170,7 +170,6 @@ class IrActionsActWindow(models.Model):
_description = 'Action Window'
_table = 'ir_act_window'
_inherit = 'ir.actions.actions'
_sequence = 'ir_actions_id_seq'
_order = 'name'
@api.constrains('res_model', 'binding_model_id')
@@ -348,7 +347,6 @@ class IrActionsActUrl(models.Model):
_description = 'Action URL'
_table = 'ir_act_url'
_inherit = 'ir.actions.actions'
_sequence = 'ir_actions_id_seq'
_order = 'name'
name = fields.Char(string='Action Name', translate=True)
@@ -386,7 +384,6 @@ class IrActionsServer(models.Model):
_description = 'Server Actions'
_table = 'ir_act_server'
_inherit = 'ir.actions.actions'
_sequence = 'ir_actions_id_seq'
_order = 'sequence,name'
DEFAULT_PYTHON_CODE = """# Available variables:
@@ -675,7 +672,6 @@ class IrActionsServer(models.Model):
class IrServerObjectLines(models.Model):
_name = 'ir.server.object.lines'
_description = 'Server Action value mapping'
_sequence = 'ir_actions_id_seq'
server_id = fields.Many2one('ir.actions.server', string='Related Server Action', ondelete='cascade')
col1 = fields.Many2one('ir.model.fields', string='Field', required=True, ondelete='cascade')
@@ -831,7 +827,6 @@ class IrActionsActClient(models.Model):
_description = 'Client Action'
_inherit = 'ir.actions.actions'
_table = 'ir_act_client'
_sequence = 'ir_actions_id_seq'
_order = 'name'
name = fields.Char(string='Action Name', translate=True)
@@ -92,7 +92,6 @@ class IrActionsReport(models.Model):
_description = 'Report Action'
_inherit = 'ir.actions.actions'
_table = 'ir_act_report_xml'
_sequence = 'ir_actions_id_seq'
_order = 'name'
name = fields.Char(translate=True)
@@ -3402,7 +3402,7 @@ class TestFieldParametersValidation(common.TransactionCase):
def insert(model, *fnames):
""" Return the expected query string to INSERT the given columns. """
columns = sorted(fnames + ('create_uid', 'create_date', 'write_uid', 'write_date'))
return 'INSERT INTO "{}" ("id", {}) VALUES (nextval(%s), {}) RETURNING id'.format(
return 'INSERT INTO "{}" ({}) VALUES ({}) RETURNING id'.format(
model._table,
", ".join('"{}"'.format(column) for column in columns),
", ".join('%s' for column in columns),
+4 -5
View File
@@ -506,7 +506,6 @@ class BaseModel(metaclass=MetaModel):
"""
_table = None #: SQL table name used by model if :attr:`_auto`
_table_query = None #: SQL expression of the table's content (optional)
_sequence = None #: SQL sequence to use for ID field
_sql_constraints = [] #: SQL constraints [(name, sql_def, message)]
_rec_name = None #: field to use for labeling records, default: ``name``
@@ -703,7 +702,6 @@ class BaseModel(metaclass=MetaModel):
""" Initialize base model attributes. """
cls._description = cls._name
cls._table = cls._name.replace('.', '_')
cls._sequence = None
cls._log_access = cls._auto
inherits = {}
depends = {}
@@ -716,7 +714,6 @@ class BaseModel(metaclass=MetaModel):
_logger.warning("The model %s has no _description", cls._name)
cls._description = base._description or cls._description
cls._table = base._table or cls._table
cls._sequence = base._sequence or cls._sequence
cls._log_access = getattr(base, '_log_access', cls._log_access)
inherits.update(base._inherits)
@@ -727,7 +724,6 @@ class BaseModel(metaclass=MetaModel):
for cons in base._sql_constraints:
cls._sql_constraints[cons[0]] = cons
cls._sequence = cls._sequence or (cls._table + '_id_seq')
cls._sql_constraints = list(cls._sql_constraints.values())
# avoid assigning an empty dict to save memory
@@ -4211,7 +4207,7 @@ Fields:
for data in data_list:
# determine column values
stored = data['stored']
columns = [('id', "nextval(%s)", self._sequence)]
columns = []
for name, val in sorted(stored.items()):
field = self._fields[name]
assert field.store
@@ -4245,6 +4241,9 @@ Fields:
# batch, to avoid regressions as much as possible.
#
# That said, we haven't closed the door completely.
if not columns: # Manage the case where we create empty record
columns = [('id', '%s', psycopg2.extensions.AsIs('DEFAULT'))]
query = "INSERT INTO {} ({}) VALUES ({}) RETURNING id".format(
quote(self._table),
", ".join(quote(name) for name, fmt, val in columns),