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

Fix dGC height, weight and BMI fields for CSV upload #524

Merged
merged 4 commits into from
Jan 29, 2025

Conversation

mbarton
Copy link
Member

@mbarton mbarton commented Jan 29, 2025

Fixes #523

The code to save these fields was in VisitForm.save(). This wasn't being called during CSV upload.

I had previously tried this with PatientForm.save() but hit two road blocks:

  • There was no asynchronous version to call
  • The ModelForm base implementation throws a ValueError if validation has failed
    • For CSV uploads we still want to save the instance anyway and errors are stored on a separate field

I've decided the best thing to do is just to call these methods, as otherwise it's likely we'll forget to update both places where derived fields need to be saved. Our overrides of save don't call super().save but that's not a problem in current versions of Django. The risk is that future versions will add functionality in there that we'll miss out on. But for CSV uploads at least the functionality is heavily unit tested at a higher level.

I've tested a 1600 row CSV (100 patients, 16 visits each) and it takes the same amount of time to upload as before, so the new sync_to_async calls don't regress performance in any practical sense.

I had previously not wanted to avoid the call to super().save in our override in ModelForm but looking again I think it's the simplest safest way to avoid this problem happening again.

I don't think the sync_to_async wrapping has regressed upload performance
@mbarton mbarton self-assigned this Jan 29, 2025
This test didn't call is_valid to then call the cleaners to get the external validation results. Didn't notice until this refactor
@mbarton mbarton merged commit 9dd34c2 into live Jan 29, 2025
1 check passed
@mbarton mbarton deleted the mbarton/dgc-results-for-csv-upload branch January 29, 2025 11:36
@mbarton
Copy link
Member Author

mbarton commented Jan 29, 2025

Seen on STAGING (merged by @mbarton 8 minutes and 46 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BMI and centiles not working for CSV uploads
1 participant