ErrorsReads and writes · rule
data.expected_version_unversioned
A write says expected_version: of an entity that keeps no RecordVersion.
Area 6, Reads and writes; not declinable; the next step is usually the agent's.
Why Jadpo refuses it
expected_version: lets a change go ahead only while the stored record
is at the version the client read, so two changes made from one copy
can't both win. That needs a version on every record: a field typed
RecordVersion, which Jadpo sets to 1 on create and moves on with every
change. An entity without one has nothing to compare, and the write
would go ahead whatever the client saw.
What it looks like
main.jadpo:
type TodoTitle = Text { max_length: 200}entity Todo { id: Uuid title: TodoTitle}type RenameTodo = Input { title: Todo.title version: Int}action rename_todo(todo_id: Todo.id, input: RenameTodo) fails TodoNotFound -> Todo { return attempt Todo.update(todo_id) { expected_version: input.version set: { title: input.title } }}
error Todo keeps no version for Todo.update to expect
--> main.jadpo:17:9
|17 | expected_version: input.version | ^^^^^^^^^^^^^^^^ no `RecordVersion`
- reason
expected_version:lets the change go ahead only while the stored version is the one the client read, so its entity keeps one: a field typedRecordVersion, which Jadpo sets to 1 on create and moves on with every change.Todohas none.- next
- Add
version: RecordVersiontoTodoand send it out and back, or removeexpected_version: ...(agent) - rule
- data.
expected_ version_ unversioned - help
- https://jadpo.
dev/docs/errors/data. expected_ version_ unversioned
(agent) at the end of the next: line means your coding agent can make
the fix itself.
How to fix it
If people change todos from a copy they read earlier, give Todo a
version, send it out with the record and back with the change, and map
a stale one in conflict::
entity Todo { id: Uuid title: TodoTitle version: RecordVersion}type RenameTodo = Input { title: Todo.title version: Todo.version}action rename_todo(todo_id: Todo.id, input: RenameTodo) fails TodoNotFound, TodoChanged -> Todo { return attempt Todo.update(todo_id) { expected_version: input.version set: { title: input.title } conflict: { Todo.version: TodoChanged } }}
A rename made from a copy someone else changed since is now refused as
TodoChanged, a 409, and the title they saved is kept.
If the last change should win, remove expected_version: ...:
action rename_todo(todo_id: Todo.id, input: RenameTodo) fails TodoNotFound -> Todo { return attempt Todo.update(todo_id) { set: { title: input.title } }}
The rename now writes whatever version the todo holds, and the input sends no version.
Related
Markdown for agents: /docs/errors/data.expected_version_unversioned.md.Built from Jadpo's main branch at commit 72d483f.