-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Users cannot delete projects with a lot of data or views and end up with 502s.
On the Dashboard's "Delete Project" page, we use Django's built-in DeleteView:
readthedocs.org/readthedocs/projects/views/private.py
Lines 167 to 180 in 38fca65
| class ProjectDelete(UpdateChangeReasonPostView, ProjectMixin, DeleteView): | |
| success_message = _('Project deleted') | |
| template_name = 'projects/project_delete.html' | |
| def get_context_data(self, **kwargs): | |
| context = super().get_context_data(**kwargs) | |
| context['is_superproject'] = ( | |
| self.object.subprojects.all().exists() | |
| ) | |
| return context | |
| def get_success_url(self): | |
| return reverse('projects_dashboard') |
It will call .delete() on the object to delete and then Django will call .delete() on any referencing FK that has on_delete=models.CASCADE
This likely becomes an issue because of FKs in models with a lot of data, such as this:
readthedocs.org/readthedocs/analytics/models.py
Lines 55 to 63 in 38fca65
| class PageView(models.Model): | |
| """PageView counts per day for a project, version, and path.""" | |
| project = models.ForeignKey( | |
| Project, | |
| related_name='page_views', | |
| on_delete=models.CASCADE, | |
| ) |
The solution is likely to clean up some relations with a bulk delete query here:
readthedocs.org/readthedocs/projects/models.py
Lines 498 to 504 in 38fca65
| def delete(self, *args, **kwargs): # pylint: disable=arguments-differ | |
| from readthedocs.projects.tasks.utils import clean_project_resources | |
| # Remove extra resources | |
| clean_project_resources(self) | |
| super().delete(*args, **kwargs) |
Metadata
Metadata
Assignees
Labels
Type
Projects
Status