Issue #4653
closedOrphan cleanup fails for some model types due to database cascade PROTECTED options
Description
When orphan cleanup goes to run it can run into problems if there are model types that refer to each other for example both AnsibleRole and AnsibleRoleVersion relate to each other and are both content types. They could have been modeled differently, but they are modeled this way for now.
This means that because you can't delete an AnsibleRole that has AnsibleRoleVersions due to cascade.PROTECTED if orphan cleanup tries to delete AnsibleRole it will fail.
For example this is a traceback showing this problem (provided by rochacbruno)
[root@fedora-29-pulp-3 ~]# systemctl status pulp-resource-manager --no-pager --full
● pulp-resource-manager.service - Pulp Resource Manager
Loaded: loaded (/etc/systemd/system/pulp-resource-manager.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-04-08 15:26:09 -03; 29min ago
Main PID: 13446 (rq)
Tasks: 1 (limit: 2351)
Memory: 57.7M
CGroup: /system.slice/pulp-resource-manager.service
└─13446 /usr/local/lib/pulp/bin/python3 /usr/local/lib/pulp/bin/rq worker -w pulpcore.tasking.worker.PulpWorker -n resource-manager@%h --pid=/var/run/pulp-resource-manager/resource-manager.pid
Apr 08 15:28:36 fedora-29-pulp-3 rq[13446]: File "/usr/local/lib/pulp/lib64/python3.7/site-packages/django/db/models/deletion.py", line 224, in collect
Apr 08 15:28:36 fedora-29-pulp-3 rq[13446]: field.remote_field.on_delete(self, field, sub_objs, self.using)
Apr 08 15:28:36 fedora-29-pulp-3 rq[13446]: File "/usr/local/lib/pulp/lib64/python3.7/site-packages/django/db/models/deletion.py", line 16, in CASCADE
Apr 08 15:28:36 fedora-29-pulp-3 rq[13446]: source_attr=field.name, nullable=field.null)
Apr 08 15:28:36 fedora-29-pulp-3 rq[13446]: File "/usr/local/lib/pulp/lib64/python3.7/site-packages/django/db/models/deletion.py", line 224, in collect
Apr 08 15:28:36 fedora-29-pulp-3 rq[13446]: field.remote_field.on_delete(self, field, sub_objs, self.using)
Apr 08 15:28:36 fedora-29-pulp-3 rq[13446]: File "/usr/local/lib/pulp/lib64/python3.7/site-packages/django/db/models/deletion.py", line 27, in PROTECT
Apr 08 15:28:36 fedora-29-pulp-3 rq[13446]: sub_objs
Apr 08 15:28:36 fedora-29-pulp-3 rq[13446]: django.db.models.deletion.ProtectedError: ("Cannot delete some instances of model 'AnsibleRole' because they are referenced through a protected foreign key: 'AnsibleRoleVersion.role'", <QuerySet [<AnsibleRoleVersion: pk=dcf32b6a-b524-4941-ae8f-54b6f1e90023>, <AnsibleRoleVersion: pk=057dd842-12b2-43e8-98c0-c75246073ed3>, <AnsibleRoleVersion: pk=f6e96f34-431d-43b9-8534-4854bd1196c1>, <AnsibleRoleVersion: pk=66adbbbb-edca-44e9-ba18-e8359dfce98d>, <AnsibleRoleVersion: pk=f98ac996-c60e-415b-affc-f5a8a5cd02e7>]>)
Apr 08 15:28:36 fedora-29-pulp-3 rq[13446]: pulp: rq.worker:WARNING: Moving job to 'failed' queue
Related issues
Updated by mdellweg over 5 years ago
Updated by bmbouter over 5 years ago
- Related to Issue #3818: The AnsibleRole as a content unit is problematic added
Updated by daviddavis over 5 years ago
- Project changed from Pulp to Ansible Plugin
Updated by bmbouter over 5 years ago
@daviddavis I was thinking this would track a possible improvement in pulpcore itself. We need to consider two questions I think
a) Are we supporting (or not) Content types that FK to each other?
b) if we are how do we do that?
Updated by daviddavis over 5 years ago
I don't think we have any support for Content that has an FK to another Content.
Updated by bmbouter over 5 years ago
Before I knew about this bug I thought it was ok to have Content foreign key to Content, but with this problem I see now that we can't. I think all we need to do is add a section to the plugin writing docs on how you cannot model foreign key relationships between Content types together? What do you think?
Updated by daviddavis over 5 years ago
- Project changed from Ansible Plugin to Pulp
- Tags Documentation added
That works I think.
Updated by bmbouter over 5 years ago
I'm thinking of moving this to CLOSED - WONTFIX once this PR is merged: https://github.com/pulp/pulpcore-plugin/pull/87
Updated by bmbouter over 5 years ago
- Status changed from NEW to MODIFIED
Applied in changeset commit:pulpcore-plugin|f4e79c1eb4d62318daf661fb7c87b3ca427365ea.
Updated by bmbouter over 5 years ago
- Status changed from MODIFIED to CLOSED - WONTFIX
The attached commit only documents for plugin writers how they can avoid this problem. The status on this issue currently is WONTFIX.