Submitting, authorizing or approving a requisition in multiple tabs (or after refreshing the page) can break its state. A status change is created, but the actual status and other properties are overwritten by the second save.
- Go to perftest.openlmis.org and log in as administrator
- Initiate a requisition for Comfort Health Clinic / Essential Meds
- Skip all except the first item, fill in all the required fields and click on the "Sync with Server" button. Wait for it to synchronize.
- Open this requisition in another, incognito tab
- In the original tab, submit the requisition
- After about 5 seconds, submit the requisition in the incognito tab
- The requisition fails to submit in the second tab and succeeds in the first one, but its status is still "Initiated"
- When trying to submit it again, an error message appears: "Failed to submit due to a duplicate status change"
What happens on the backend:
Assumptions: Save takes a considerable amount of time (say >15 seconds)
- The first synchronize / submit is called and shortly after a concurrent update is invoked
- Since the first update did not finish yet, the second update passes the validation we have (based on last updated date timestamp)
- The first update finishes and submit is invoked
- The requisition is successfully submitted and status change table is updated with new status change
- The second update finishes and overwrites what happened in previous save (most importantly status, but all other properties can be overwritten too)
Please reach the tech committee with the proposed solution first, either on the call or via dev group.