Skip to content

Commit 912c30e

Browse files
authored
fix(submissions): inject rootUuid in bulk edit operations (#5905)
### 📣 Summary Ensures that bulk submission edits include the `rootUuid` to match the behavior of single edits. ### 📖 Description This PR fixes an inconsistency between single and bulk submission edits. Previously, only single edits injected the `rootUuid` into the submission XML, while bulk edits did not, leading to discrepancies in how submission versions were linked and tracked.
1 parent a15e737 commit 912c30e

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

kpi/deployment_backends/base_backend.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ def bulk_update_submissions(
169169
deprecated_id = get_or_create_element(
170170
xml_parsed, self.SUBMISSION_DEPRECATED_UUID_XPATH
171171
)
172+
173+
# If the submission has been edited before, it will already contain
174+
# a rootUuid element - otherwise create a new element
175+
root_uuid = get_or_create_element(
176+
xml_parsed, self.SUBMISSION_ROOT_UUID_XPATH
177+
)
178+
179+
if not root_uuid.text:
180+
root_uuid.text = instance_id.text
181+
172182
deprecated_id.text = instance_id.text
173183
instance_id.text = uuid_formatted
174184

kpi/deployment_backends/openrosa_backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ def prepare_bulk_update_response(backend_results: list[dict]) -> dict:
972972
results.append(
973973
{
974974
'uuid': uuid,
975+
'root_uuid': backend_result['result'].root_uuid,
975976
'status_code': status_code,
976977
'message': message,
977978
}

kpi/tests/api/v2/test_api_submissions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,26 @@ def test_bulk_update_submissions_allowed_as_owner(self):
23762376
assert response.status_code == status.HTTP_200_OK
23772377
self._check_bulk_update(response)
23782378

2379+
# Not really testing the API, but let's validate everything is in place
2380+
# with the ORM, i.e.: instance.xml contains a <meta/rootUuid> node that matches
2381+
# with instance.root_uuid
2382+
instances = Instance.objects.filter(
2383+
pk__in=self.updated_submission_data['submission_ids']
2384+
)
2385+
for instance in instances:
2386+
for result in response.data['results']:
2387+
if result['uuid'] == instance.uuid:
2388+
assert instance.root_uuid == result['root_uuid']
2389+
xml_parsed = fromstring_preserve_root_xmlns(instance.xml)
2390+
root_uuid = xml_parsed.find(
2391+
self.asset.deployment.SUBMISSION_ROOT_UUID_XPATH
2392+
)
2393+
assert root_uuid is not None
2394+
assert result['root_uuid'] == remove_uuid_prefix(
2395+
root_uuid.text
2396+
)
2397+
break
2398+
23792399
@pytest.mark.skip(
23802400
reason=(
23812401
'Useless with the current implementation of'

0 commit comments

Comments
 (0)