Skip to content

Commit

Permalink
Make deleting a project purge the cache (#2849)
Browse files Browse the repository at this point in the history
  • Loading branch information
di authored Jan 29, 2018
1 parent 65fc7a7 commit 14a8c15
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions warehouse/admin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,22 @@ def remove_project(project, request):
(request.db.execute(release_classifiers.delete()
.where(release_classifiers.c.name ==
project.name)))
request.db.query(Release).filter(Release.name == project.name).delete()
request.db.query(Project).filter(Project.name == project.name).delete()

# Load the following objects into the session and individually delete them
# so they are included in `session.deleted` and their cache keys are purged

# Delete releases first, otherwise they will get cascade-deleted by the
# project deletion and won't be purged
for release in (
request.db.query(Release)
.filter(Release.name == project.name)
.all()):
request.db.delete(release)

# Finally, delete the project
request.db.delete(
request.db.query(Project).filter(Project.name == project.name).one()
)

request.session.flash(
f"Successfully deleted the project {project.name!r}.",
Expand Down

0 comments on commit 14a8c15

Please sign in to comment.