Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

nle-odoo
Copy link
Contributor

opw-2148046

@nle-odoo nle-odoo added the OE the report is linked to a support ticket (opw-...) label Nov 28, 2019
@nle-odoo nle-odoo force-pushed the 13.0-models-py-opw-2148046-nle branch from dfc65e3 to 5f2b681 Compare November 28, 2019 18:08
@robodoo robodoo added seen 🙂 CI 🤖 Robodoo has seen passing statuses labels Nov 28, 2019
@nle-odoo nle-odoo force-pushed the 13.0-models-py-opw-2148046-nle branch from 5f2b681 to 1e20d0b Compare November 29, 2019 15:56
@robodoo robodoo removed the CI 🤖 Robodoo has seen passing statuses label Nov 29, 2019
@nle-odoo nle-odoo force-pushed the 13.0-models-py-opw-2148046-nle branch from 1e20d0b to 1b2c242 Compare November 29, 2019 16:19
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
@nle-odoo nle-odoo force-pushed the 13.0-models-py-opw-2148046-nle branch from 1b2c242 to b34e14b Compare November 29, 2019 16:34
@nle-odoo nle-odoo closed this Nov 29, 2019
@nle-odoo nle-odoo deleted the 13.0-models-py-opw-2148046-nle branch November 29, 2019 16:35
@nle-odoo nle-odoo restored the 13.0-models-py-opw-2148046-nle branch November 29, 2019 16:35
@nle-odoo
Copy link
Contributor Author

nle-odoo commented Nov 29, 2019

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 ondelete="cascade", so the simplest solution seems to be:

  • for v13 explicitly remove parents from child nodes (then the orm write will do what's needed)

  • for master: set ondelete="cascade" on the field parent_id of product.public.category (this will be adapted in forward-port)

robodoo r+

@nle-odoo nle-odoo reopened this Nov 29, 2019
@robodoo robodoo added CI 🤖 Robodoo has seen passing statuses and removed closed 💔 labels Nov 29, 2019
@nle-odoo
Copy link
Contributor Author

nle-odoo commented Dec 2, 2019

robodoo r+

@fmdl
Copy link
Contributor

fmdl commented Dec 2, 2019

@rco-odoo it an exemple of the isssue with the SQL cascade.

#33113

regards

@nle-odoo nle-odoo deleted the 13.0-models-py-opw-2148046-nle branch December 2, 2019 14:26
nle-odoo added a commit to odoo-dev/odoo that referenced this pull request Dec 2, 2019
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
robodoo pushed a commit that referenced this pull request Dec 2, 2019
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI 🤖 Robodoo has seen passing statuses OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants