When an object is shared and has on_delete=SET_NULL all other objects lose reference to it
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 598
- Forks
- 168
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 86
Description
We have number of instances where in our models we use on FK on_detete=SET_NULL
[ipanova@puffy models]$ git grep SET_NULL
exporter.py: "PulpExport", related_name="last_export", on_delete=models.SET_NULL, null=True
publication.py: content_guard = models.ForeignKey(ContentGuard, null=True, on_delete=models.SET_NULL)
publication.py: remote = models.ForeignKey(Remote, null=True, on_delete=models.SET_NULL)
publication.py: content_guard = models.ForeignKey(ContentGuard, null=True, on_delete=models.SET_NULL)
publication.py: publication = models.ForeignKey(Publication, null=True, on_delete=models.SET_NULL)
publication.py: remote = models.ForeignKey(Remote, null=True, on_delete=models.SET_NULL)
publication.py: Repository, null=True, on_delete=models.SET_NULL, related_name="distributions"
publication.py: repository_version = models.ForeignKey(RepositoryVersion, null=True, on_delete=models.SET_NULL)
repository.py: remote = models.ForeignKey("Remote", null=True, on_delete=models.SET_NULL)
repository.py: base_version = models.ForeignKey("RepositoryVersion", null=True, on_delete=models.SET_NULL)
task.py: worker = models.ForeignKey("Worker", null=True, related_name="tasks", on_delete=models.SET_NULL)
task.py: "Task", null=True, related_name="child_tasks", on_delete=models.SET_NULL
task.py: "TaskGroup", null=True, related_name="tasks", on_delete=models.SET_NULL
Examples:
In a situation where a remote is being shared/user by number of repositories by removing the remote all repos will lose reference to the remote.
Same stands for content_guards and N distributions that use same content_guard. Once the content_guard is removed, all distributions that were using it will stop serving protected content.
Deleting objects that are used as FK with on_delete=SET_NULL can break stuff, open security holes, or just produce unexpected results for the users, since it is impossible to query what distributions use certain content guard, or what repos user certain remote before making a decision whether it is safe or desirable to remove that object.
What would be potentials steps:
- should we protect objects from being deleted if they are used in other objects?
- do nothing, document
- other?
https://pulp.plan.io/issues/8305 is a special variant of this issue
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the SET_NULL usages in exporter.py, publication.py, repository.py, and task.py, then compare the concern with issue 8305. The issue asks whether to protect deletion, document the behavior, or take another approach, so a concrete definition of done is not provided.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100