Add on_delete to ForeignKey definitions.

Review Request #11988 — Created Jan. 24, 2022 and submitted — Latest diff uploaded

Information

Review Board
master

Reviewers

Django has made the on_delete argument to ForeignKey mandatory.
Until now, this has defaulted to CASCADE, which makes it easy to
unintentionally delete things that shouldn't be deleted. Making it a
required argument forces developers to think about each model and how it
should behave.

This change explicitly sets on_delete for every relation we have. Most
of these are CASCADE, but the diff data ones are SET_NULL because
those are effectively a one-to-many relation, and we don't want to
delete diff data that may be shared by other diffs.

Ran unit tests.

Diff Revision 3 (Latest)

orig
1
2
3

Commits

First Last Summary ID Author
Add on_delete to ForeignKey definitions.
Django has made the `on_delete` argument to `ForeignKey` mandatory. Until now, this has defaulted to `CASCADE`, which makes it easy to unintentionally delete things that shouldn't be deleted. Making it a required argument forces developers to think about each model and how it should behave. This change explicitly sets `on_delete` for every relation we have. Most of these are `CASCADE`, but the diff data ones are `SET_NULL` because those are effectively a one-to-many relation, and we don't want to delete diff data that may be shared by other diffs. Testing Done: Ran unit tests.
a6eb4c8323c57a65ff0f425ab8ac8ec907436ea4 David Trowbridge
reviewboard/accounts/models.py
reviewboard/attachments/models.py
reviewboard/changedescs/models.py
reviewboard/diffviewer/models/diffcommit.py
reviewboard/diffviewer/models/diffset.py
reviewboard/diffviewer/models/filediff.py
reviewboard/hostingsvcs/models.py
reviewboard/integrations/models.py
reviewboard/notifications/models.py
reviewboard/oauth/models.py
reviewboard/reviews/models/base_comment.py
reviewboard/reviews/models/default_reviewer.py
reviewboard/reviews/models/diff_comment.py
reviewboard/reviews/models/file_attachment_comment.py
reviewboard/reviews/models/group.py
reviewboard/reviews/models/review.py
reviewboard/reviews/models/review_request.py
reviewboard/reviews/models/review_request_draft.py
reviewboard/reviews/models/screenshot_comment.py
reviewboard/reviews/models/status_update.py
reviewboard/scmtools/models.py
reviewboard/webapi/models.py
Loading...