-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
Reject Duplicate Submissions #5047
base: main
Are you sure you want to change the base?
Conversation
28eefe5
to
039ed95
Compare
039ed95
to
6a177da
Compare
# Conflicts: # kobo/apps/openrosa/apps/logger/exceptions.py # kobo/apps/openrosa/apps/logger/models/instance.py # kobo/apps/openrosa/apps/logger/models/xform.py # kobo/apps/openrosa/apps/logger/xform_instance_parser.py # kobo/apps/openrosa/libs/utils/logger_tools.py
kobo/apps/openrosa/apps/api/tests/viewsets/test_xform_submission_api.py
Outdated
Show resolved
Hide resolved
…-reject_duplicate_submissions
bf597d5
to
2958052
Compare
- Add test case for duplicate submission with an attachment - Improve logic to extract UUID from xml - Add logic to reject submission without UUID
2958052
to
f3c89f6
Compare
…together constraint
86e9313
to
306888b
Compare
# Conflicts: # kobo/apps/openrosa/apps/api/tests/viewsets/test_xform_submission_api.py # kobo/apps/openrosa/apps/logger/tests/test_simple_submission.py # kobo/apps/openrosa/apps/logger/xform_instance_parser.py # kobo/apps/openrosa/libs/utils/logger_tools.py
# Conflicts: # kobo/apps/openrosa/libs/utils/logger_tools.py
5f50949
to
362bfa8
Compare
a1284fd
to
578b2be
Compare
int_lock = int.from_bytes( | ||
hashlib.shake_128( | ||
f'{xform_id}!!{submission_uuid}!!{xml_hash}'.encode() | ||
).digest(7), 'little' | ||
) | ||
acquired = False |
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.
@rajpatel24 please write a comment to explain why we use this thing.
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.
The code looks good. We don't have preview steps, though, should we?
578b2be
to
b0a4208
Compare
Indeed, but this PR predates the new PR workflow. |
Checklist
Description
We have identified a race condition in the submission processing that causes duplicate submissions with identical UUIDs and XML hashes. This issue is particularly problematic under conditions with multiple remote devices submitting forms simultaneously over unreliable networks.
To address this issue, a PR has been raised with the following proposed changes:
Race Condition Resolution: A locking mechanism has been added to prevent the race condition when checking for existing instances and creating new ones. This aims to eliminate duplicate submissions.
UUID Enforcement: Submissions without a UUID are now explicitly disallowed. This ensures that every submission is uniquely identifiable and further mitigates the risk of duplicate entries.
Introduction of
root_uuid
:To ensure a consistent submission UUID throughout its lifecycle and prevent duplicate submissions with the same UUID, a new
root_uuid
column has been added to theInstance
model with a unique constraint (root_uuid
perxform
).If the
<meta><rootUuid>
is present in the submission XML, it is stored in theroot_uuid
column.If
<meta><rootUuid>
is not present, the value from<meta><instanceID>
is used instead.This approach guarantees that the
root_uuid
remains constant across the lifecycle of a submission, providing a reliable identifier for all instances.UUID Handling Improvement: Updated the logic to strip only the
uuid:
prefix while preserving custom, non-UUID ID schemes (e.g., domain.com:1234). This ensures compliance with the OpenRosa spec and prevents potential ID collisions with custom prefixes.Error Handling:
These changes should improve the robustness of the submission process and prevent both race conditions and invalid submissions.
Notes
Related issues
Supersedes kobotoolbox/kobocat#876