Skip to content
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

Added a form deletion script for genie requests #35514

Merged
merged 6 commits into from
Dec 12, 2024

Conversation

mjriley
Copy link
Contributor

@mjriley mjriley commented Dec 12, 2024

Product Description

Technical Summary

Associated ticket: https://dimagi.atlassian.net/browse/SAAS-16071
This is a PR in response to a genie request to delete forms for a client. This PR creates a script to give us a command to run in the future.

The command is intended to be run as:
./manage.py delete_forms <domain> <path_to_csv_file>
and we can record a log by piping its output to tee.

Safety Assurance

Safety story

Verified this locally, by creating new forms, and putting those form IDs (and bogus form IDs) inside a csv file.

Automated test coverage

Added new tests to verify the changes made to hard_delete_forms

QA Plan

No QA

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Labels & Review

  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@mjriley mjriley added the product/invisible Change has no end-user visible impact label Dec 12, 2024
@mjriley mjriley requested a review from snopoke as a code owner December 12, 2024 00:34
@dimagimon dimagimon added the Risk: High Change affects files that have been flagged as high risk. label Dec 12, 2024
parser.add_argument('--resume_id', help='form ID to start at, within the CSV file')

def handle(self, domain, filename, resume_id=None, **options):
# expects the filename to have a CSV with a header containing "Deletion Status" and "Form ID" fields
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually use the "Deletion Status" field? I only see the "Form ID" field being used. My thinking here is if there is a Deletion Status field with values under it, someone's going to expect those values to be used for something, and if we're not going to use them, then we should require the CSV not have that column.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working with the CSV that Enveritas submitted to us. If I simplify this script to expect a sheet without that column, then I'd need to write another script to port the Envertias CSV over. Do you think that's something we should do long term?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 4fccff9. As mentioned offline, I think the process going forward should be that customers making this request provide us a CSV file that only contains a single column representing form ID. In this case, the customer provided an initial column called "Deletion Status" which only seems to contain ready_to_request. However, if one of the rows contained something like do_not_delete instead, we wouldn't want to have the responsibility for interpreting that field.

form_ids = [row[INDEX_FORM_ID] for row in chunk]

try:
deleted_form_ids = set(XFormInstance.objects.hard_delete_forms(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel squeemish about hard-delete, though obviously it is what we're being asked to do. An alternate pattern would be to soft delete and mark for automatic hard-deletion in 90 days. But that is probably overkill for the present situation. Maybe what I would ask is just to rename the command to hard_delete_forms.py, since in some places delete means soft-delete, and making that name explicit will remove any kind of ambiguity for anyone reusing this script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I can definitely do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed with 4fccff9

Copy link
Member

@dannyroberts dannyroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good to me, one minor thing

parser.add_argument('--resume_id', help='form ID to start at, within the CSV file')

def handle(self, domain, filename, resume_id=None, **options):
# expects the filename to have a CSV with a header containing "Deletion Status" and "Form ID" fields
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is wrong now?

@mjriley mjriley merged commit e67f804 into master Dec 12, 2024
13 checks passed
@mjriley mjriley deleted the mjr/form-deletion-script branch December 12, 2024 19:01
Copy link

sentry-io bot commented Dec 18, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ FileNotFoundError: [Errno 2] No such file or directory: '/tmp/form_ids.csv' corehq.apps.cleanup.management.commands.hard_de... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product/invisible Change has no end-user visible impact Risk: High Change affects files that have been flagged as high risk.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants