Skip to content

fix(expressions): list elements set past the end append in order of their index - #103

Merged
kalaspuff merged 3 commits into
mainfrom
fctl/53-https-github-com-kalaspuff-dynamoxy-issu
Oct 30, 2026
Merged

kalaspuff merged 3 commits into
mainfrom
fctl/53-https-github-com-kalaspuff-dynamoxy-issu

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The update evaluator assigned SET actions in the order of the expression, and an index at or past the end of a list appends. So SET l[4] = :b, l[3] = :a on [x, y, z] appended b, then overwrote it with a, and stored [x, y, z, a]; SET l[9] = :b, l[5] = :a stored b before a. DynamoDB sets the elements of a list in order of their index ("If you add multiple elements in a single SET operation, the elements are sorted in order by element number", the update expressions guide) and stores [x, y, z, a, b] in both cases. The in-memory backend stored the wrong list, and since transactions refresh instances with the same evaluator (_core._apply_update), an instance updated in a transaction on AWS could differ from the stored item too.

SET actions are now assigned in path order, which sets the elements of each list in order of their index; their values are still evaluated against the item before the update. That covers UpdateItem, transactions, PartiQL updates and the refresh of instances.

Verified with an evaluator test of the issue's cases, a mix of replaced and appended elements, and lists inside maps and lists, and with a transaction test whose refreshed instance lost b on both backends before the fix. dynoxide-rs's tests captured against DynamoDB (eu-west-2) show the same orders. MiniStack applies the actions in their order (it stores [x, y, z, a], through UpdateItem and TransactWriteItems alike), so the transaction test compares the stored item on the in-memory backend only.

Fixes #74

Checklist

  • Tests cover the change (in-memory backend; the transaction test also runs on MiniStack, for the refreshed instance)
  • Docs updated (changelog; the guides do not describe the order of list elements)
  • make check passes locally (lint, types, clippy, consistency, Rust and Python tests)
  • Breaking change? No

Worth confirming

  • Assumption: a path through an element past the end of a list (SET l[4] = :m, l[3].k = :a on a three-element list) is now refused whatever the order of the actions. DynamoDB refuses such a path when it is the only action (also captured by dynoxide-rs), and the index order puts l[3] before l[4], but this combination was not captured; before, the in-memory backend wrote into the appended map when the append came first.
  • Assumption: ADD on list elements past the end (ADD l[7] :one, l[5] :two) still applies in the order of the actions, since DynamoDB documents the index order only for SET.

fctl session


Note

Low risk. It changes only the order in which SET actions are assigned in the update evaluator, which matters only when several elements are set past the end of the same list, and it adds tests.

What it does. The update evaluator now assigns SET actions in path order, so elements set past the end of a list are appended in order of their index, as DynamoDB does, instead of in the order of the actions. This fixes the in-memory backend and the local refresh of instances after a transaction, which could store or show a list with an element lost. Values are still evaluated against the item before the update. The newer commits only merge main into the branch and do not touch the change.

Stricter paths. A path through an element past the end of a list (SET l[4] = :m, l[3].k = :a) is now refused whatever the order of the actions; before, the in-memory backend accepted it when the append came first.

fctl review's first look at 121f91d · 3 files, +61 −3 · Review agent settings

fctl-sh Bot and others added 3 commits October 30, 2026 23:22
…heir index

The update evaluator assigned SET actions in the order of the
expression, and an index at or past the end of a list appends. So
`SET l[4] = :b, l[3] = :a` on `[x, y, z]` appended `b` at index 3 and
then overwrote it with `a`, storing `[x, y, z, a]`, and
`SET l[9] = :b, l[5] = :a` stored `b` before `a`. DynamoDB sets the
elements of a list in order of their index ("If you add multiple
elements in a single SET operation, the elements are sorted in order by
element number", the update expressions guide) and stores
`[x, y, z, a, b]` in both cases.

The in-memory backend stored the wrong list, and since transactions
refresh instances with the same evaluator, instances updated in a
transaction on AWS could differ from the stored item too.

SET actions are now assigned in path order, which sets the elements of
each list in order of their index. A path through an element past the
end (`l[3].k` on a three-element list) is therefore refused whatever
the order of the actions, as it is when it is the only action.

Fixes #74

Co-authored-by: Carl Oscar Aaro <[email protected]>
Keeps both CHANGELOG.md entries under Fixed: the one for optional
fields with a codec of their own (#105), then this branch's for list
elements set past the end.

Co-authored-by: Carl Oscar Aaro <[email protected]>
Keeps both CHANGELOG.md entries under Fixed: the one for PartiQL
transactions that name an item twice (#104), then this branch's for
list elements set past the end.

Co-authored-by: Carl Oscar Aaro <[email protected]>
@kalaspuff
kalaspuff merged commit 5365c31 into main Oct 30, 2026
22 checks passed
@kalaspuff
kalaspuff deleted the fctl/53-https-github-com-kalaspuff-dynamoxy-issu branch October 30, 2026 23:50
fctl-sh Bot added a commit that referenced this pull request Oct 30, 2026
…com-kalaspuff-dynamoxy-issu

Brings in #103 (list elements set past the end append in order of
their index). CHANGELOG.md conflicted where both added an entry at the
end of [Unreleased] Fixed: both entries are kept, #103's first.

Co-authored-by: Carl Oscar Aaro <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SET of several list elements past the end applies them in expression order and loses values

1 participant