[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
This commit is contained in:
committed by
Raphael Collet
parent
ae41be0c5c
commit
3189b031a2
+8
-15
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user