From 3189b031a28b323f08eda3e9f99f6687cc7b05c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Fri, 14 Jan 2022 07:57:42 +0000 Subject: [PATCH] [REF] base: simplify the `_write` Issue: `_write` checked that the number of modified row in DB was equal to the number of ids in the RecordSet (raise `MissingError` if not). This behavior was only used by the ORM to retry (with exists() on the RecordSet before) if the Missing Error raised. Then it makes the job a second time (for no reason). Then: - Remove the check of number of row (and simplify the call of `_write`) - Remove the useless return value (always `True`) - Remove the `set(` before the `split_for_in_conditions`, it adds randomness for nothing because the `_write` should be call without duplicate id (even if it is not the case, we don't care). task-2735546 Part-of: odoo/odoo#82727 --- odoo/models.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/odoo/models.py b/odoo/models.py index ebc42196804..f72c068f991 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -3922,9 +3922,13 @@ Fields: return True def _write(self, vals): - # low-level implementation of write() + """ Low-level implementation of write() + + The ids of self should be a database id and unique. + Ignore non-existent record. + """ if not self: - return True + return self._check_concurrency() cr = self._cr @@ -3958,20 +3962,13 @@ Fields: template = ', '.join(f'"{name}" = %s' for name in columns) query = f'UPDATE "{self._table}" SET {template} WHERE id IN %s' params = list(columns.values()) - for sub_ids in cr.split_for_in_conditions(set(self.ids)): + for sub_ids in cr.split_for_in_conditions(self._ids): cr.execute(query, params + [sub_ids]) - if cr.rowcount != len(sub_ids): - raise MissingError( - _('One of the records you are trying to modify has already been deleted (Document type: %s).', self._description) - + '\n\n({} {}, {} {})'.format(_('Records:'), sub_ids[:6], _('User:'), self._uid) - ) # update parent_path if parent_records: parent_records._parent_store_update() - return True - @api.model_create_multi @api.returns('self', lambda value: value.id) def create(self, vals_list): @@ -5700,11 +5697,7 @@ Fields: updates[frozendict(vals)].append(rid) for vals, ids in updates.items(): - recs = model.browse(ids) - try: - recs._write(vals) - except MissingError: - recs.exists()._write(vals) + model.browse(ids)._write(vals) if fnames is None: # flush everything