DHIS-21957 Skip data values for closed orgunits before dataValueSets POST - #15
Open
KatherineWyers wants to merge 2 commits into
Open
KatherineWyers wants to merge 2 commits into
KatherineWyers wants to merge 2 commits into
Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Problem
The outlier detection stage batches all data values for a dataset into a single dataValueSets POST. If any org unit in that batch is closed (has a closedDate or has an openingDate after the submitted period) DHIS2 correctly rejects the value. But since everything is posted together, the entire batch fails with a 409 Conflict, including valid data for org units that are open and valid data for org units that are closed in a later period but open during that period.
This is expected DHIS2 behaviour. Not a DHIS2 bug.
Jira: DHIS2-21957 https://dhis2.atlassian.net/browse/DHIS2-21957
Fix
Make a chunked call to the API to get the opened and closed dates for the org units.
Create helper functions to determine whether to keep or skip the orgunit:period combination.
should_keep_data_value(): compares a data value's period against an org unit's openingDate and closingDate.
get_organisation_unit_dates_bulk(): fetches the openingDate and closingDate for many org unites in one request. This is chunked, so it doesn't go above the API limit of DHIS2.
filter_and_fetch_closed_org_units(): Fetch the dates for the org units referenced in a batch and filters them by (orgUnit, period) pairs.
This fix is wired into _process_tasks() in cli.py right before posting. Orgunit:period pairs that are filtered out are logged individually and they are displayed to the user as 'org unit closed'.
What is unchanged
the 'deletes' and 'integrity_payloads' are unaffected. This fix only filters the outlier-stage for the 'upserts'. It is worth discussing whether deletes and integrity_payloads also need this same fix.
Testing
All new tests use mocked aiohttp sessions, so no real network or DHIS2 calls.
tests/test_org_unit_filter.py: Testing the boundary cases for should_keep_data_value.
tests/test_api_utils.py: Testing the chunking for get_organisation_unit_dates_bulk