New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] models.py: update parent_path on unlink #41075
Conversation
dfc65e3
to
5f2b681
Compare
5f2b681
to
1e20d0b
Compare
1e20d0b
to
1b2c242
Compare
In the case of deletion with `ondelete="set null"`, return_path of children of deleted record will not have return_path updated. So remove the parent explicitely so the ORM know to update them. note: in master the parent_id field of product.public.category will be set to `ondelete="cascade"`. opw-2148046 closes odoo#41075
1b2c242
to
b34e14b
Compare
there has been some version of this commit: diff --git a/odoo/models.py b/odoo/models.py
index cf01b31a65b17..0b7e67c5bed55 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -3301,6 +3301,11 @@ def unlink(self):
if self.env['ir.property'].search([('res_id', '=', False), ('value_reference', 'in', refs)]):
raise UserError(_('Unable to delete this document because it is used as a default property'))
+ # determine records that require updating parent_path
+ child_records = self.browse()
+ if self._parent_store:
+ child_records = self.search([(self._parent_name, 'child_of', self.ids)]) - self
+
# Delete the records' properties.
with self.env.norecompute():
self.check_access_rule('unlink')
@@ -3349,6 +3354,10 @@ def unlink(self):
if attachments:
ir_attachment_unlink |= attachments.sudo()
+ # update parent_path
+ if child_records:
+ child_records._parent_store_update()
+
# invalidate the *whole* cache, since the orm does not handle all
# changes made in the database, like cascading delete!
self.invalidate_cache() and diff --git a/odoo/models.py b/odoo/models.py
index cf01b31a65b17..b0dd16b1c598e 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -3301,6 +3301,10 @@ def unlink(self):
if self.env['ir.property'].search([('res_id', '=', False), ('value_reference', 'in', refs)]):
raise UserError(_('Unable to delete this document because it is used as a default property'))
+ # update child records return_path
+ if self._parent_store and self._fields[self._parent_name].ondelete == 'set null':
+ self.search([(self._parent_name, '=', self.ids)])[self._parent_name] = None
+
# Delete the records' properties.
with self.env.norecompute():
self.check_access_rule('unlink') but these solutions still have an issue in the case of deletion of records through a
robodoo r+ |
robodoo r+ |
In the case of deletion with `ondelete="set null"`, return_path of children of deleted record will not have return_path updated. So remove the children recursively. Another fix was done in 13.0 to avoid most issue in 6d5cd8b. opw-2148046 closes odoo#41075 X-original-commit: 6d5cd8b
In the case of deletion with `ondelete="set null"`, return_path of children of deleted record will not have return_path updated. So remove the children recursively. Another fix was done in 13.0 to avoid most issue in 6d5cd8b. opw-2148046 closes #41075 closes #41178 X-original-commit: 6d5cd8b Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
opw-2148046