Stale Data
The stale data
error occurs when Corteza detects that a request attempted to change a resource that was already changed by another request.
Example: Bulk record update
The example utilizes batch record creation where we are trying to update the record $RECORD_ID
twice.
curl -X POST "$BASE_URL/api/compose/namespace/$NAMESPACE_ID/module/$MODULE_ID/record/" \
-H 'accept: application/json, text/plain, */*' \
-H "authorization: Bearer $JWT" \
-H 'content-type: application/json' \
--data-raw "{
\"records\": [{
\"set\": [{
\"recordID\": \"$RECORD_ID\",
\"moduleID\": \"$MODULE_ID\",
\"values\": [{ \"name\": \"name\", \"value\": \"Some value\" }],
\"namespaceID\": \"$NAMESPACE_ID\",
\"createdAt\": \"2022-02-17T11:44:20Z\",
\"updatedAt\": \"2022-02-17T17:13:42Z\"
},
{
\"recordID\": \"$RECORD_ID\",
\"moduleID\": \"$MODULE_ID\",
\"values\": [{ \"name\": \"name\", \"value\": \"Some OTHER value\" }],
\"namespaceID\": \"$NAMESPACE_ID\",
\"createdAt\": \"2022-02-17T11:44:20Z\",
\"updatedAt\": \"2022-02-17T17:13:42Z\"
}]
}]
}" \
--compressed
The stale data
error occurs because the first record causes the resource to change on the server.
When the second resource is handled, the current resource on the server is no longer the one that the second record is referencing.
To solve the issue, either split the request in two or determine the latest version locally before sending the request.
Example: Workflow execution
The example utilizes the fork
gateway where we first fetch the record and then attempt to update the same instance twice.
Because one resolves before the other, the second one raises a stale data
error
Use the two fork branches to update the values without saving the record to solve the issue.
Save the record at the very end when all of the values are set to what they should be.