Problem/Motivation

State variable is used as an auto number generator with the incrementor (say +1) and for concurrent updates/save, the latest value is not reflected.

Steps to reproduce

Its like a live grievance submission system where we use state as auto number to assign each grievance an unique id. This unique id got duplicated using state variable and it was almost 2 seconds gap (almost concurrent submission) where live user record their submissions.

Proposed resolution

Is there a way for state variable to support concurrent updates which can be read? Any alternate suggestions form the forum is much appreciated.

Remaining tasks

Not applicable

User interface changes

Not applicable

API changes

Not applicable

Data model changes

Not applicable

Release notes snippet

Not applicable

Comments

partv76 created an issue. See original summary.

larowlan’s picture

Issue tags: -state, -concurrent

Use the sequences table or the lock api

longwave’s picture

Status: Active » Fixed

It sounds like these submissions should either be entities with a uniquely generated ID on insert, or if you really need custom code here use the sequences table or the lock API as suggested above. As you have found, the state API probably isn't the right place to do this sort of thing.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.