-
Notifications
You must be signed in to change notification settings - Fork 633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Facility deletion management command #7033
Facility deletion management command #7033
Conversation
In later versions of Django, it now requires an explicit `on_delete` option instead of defaulting to CASCADE
076ab31
to
36af42b
Compare
Codecov Report
|
post_delete.receivers = self.receivers | ||
self.receivers = None | ||
|
||
|
||
def _interactive_client_facility_selection(): | ||
facilities = Facility.objects.all().order_by("name") | ||
message = "Please choose a facility to sync:\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjester Is the use of sync
here intentional? This command should delete the facility, so why sync...? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@radinamatic Oh good catch! I didn't notice it said "sync". I'll make that dynamic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here a41de91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not reviewing before -- looks great! Just added a couple comment typo notes and a random comment. Nothing needing action.
|
||
|
||
class Command(AsyncCommand): | ||
help = "This command initiates the deletion process for a facility and all of it's related data." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*its
"ARE YOU SURE? If you do this, there is no way to recover the facility data on this device." | ||
) | ||
|
||
# everything should get cascade deleted from the facility, but we'll check anyway |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. The main thing that I could imagine might be less likely to cascade delete would be anonymous ContentSessionLogs, which don't FK onto a user. But they would still have an FK onto the FacilityDataset (as would all of these), so it should all get cascade deleted, yeah.
update_progress(increment=0, message="Counting database objects") | ||
total_count = delete_group.count(update_progress) | ||
|
||
# no the deleting step |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*now?
Summary
facilitytask
endpoint for initiating a facility deletion taskon_delete=CASCADE
to the models since it in future versions of Django, it requires an explicit action it instead of assuming cascade@action
decorators with preferred alternative since it is deprecatedReviewer guidance
A nice to have feature was to have the command report progress. Relying on CASCADE deletions works just fine for most of the models, but also doesn't give much insight into that progress, as far as I know. This currently goes through all the models, counts them, and then deletes them; through this procedure it can report progress since it's handling the models individually.
Some feedback on whether we care about any of that would be great. It was a nice to have that didn't seem too difficult, but could get stale in the future if adding more related models, although still completely deleting the facility because of the cascade.
References
Notion page
Contributor Checklist
PR process:
If this includes an internal dependency change, a link to the diff is providedTesting:
If there are any front-end changes, before/after screenshots are includedReviewer Checklist
yarn
andpip
)