Skip to content

fix(memory): PartiQL and expressions follow DynamoDB's rules, and hand-written conditions get no redundant parentheses - #135

Merged
kalaspuff merged 4 commits into
issues-stack/9-binding-conversionsfrom
issues-stack/10-memory-parity
Oct 31, 2026
Merged

kalaspuff merged 4 commits into
issues-stack/9-binding-conversionsfrom
issues-stack/10-memory-parity

Conversation

@fctl-sh

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

Copy link
Copy Markdown
Contributor

What and why

The in-memory DynamoDB handled PartiQL and expressions differently from DynamoDB (#97), so tests passed where production fails. It now follows DynamoDB's rules and messages, as dynoxide-rs captured them against DynamoDB (its tests and notes give regions and dates):

  • PartiQL batches:
    • A BatchExecuteStatement that mixes reads and writes is refused ("Read and write requests together in the same batch is not supported."), and so is one that names an item twice ("Provided list of item keys contains duplicates"). Both are refused before any statement runs.
    • ReturnValuesOnConditionCheckFailure=ALL_OLD returns the stored item in BatchStatementError.Item.
    • Reads of a missing table fail with ResourceNotFound, and unkeyed reads have DynamoDB's message.
  • PartiQL transactions:
    • RETURNING is refused with "Validation failed in TransactStatements[i]: RETURNING clause is not supported in ExecuteTransaction."
    • Mixed transactions and unkeyed reads have DynamoDB's messages, and tokens longer than 36 characters are refused.
    • ALL_OLD returns the stored item in CancellationReason.Item.
  • PartiQL statements:
    • Refused: an UPDATE or DELETE that gives a key attribute two values ("Multiple conditions on same key pk ..."), DELETE ... RETURNING ALL NEW *, writes to an index, exists() ("Unrecognized function: exists at 1:45:6", positions included), and Limit=0.
    • set_add/set_delete with another attribute than the one assigned, or with a value that is not a set, are refused, with DynamoDB's positions. Before, set_add(n, 5) added 5 to a number.
    • attribute_exists() and attribute_not_exists() work.
    • Negative numbers after keywords parse (n BETWEEN -5 AND 5, ... OR -3 < n).
  • PartiQL capacity: reads report capacity in the requested detail (INDEXES included), a DELETE of a missing item costs a write, and batch reads and read transactions report their reads. Transactions double the table's write units but not the indexes', for TransactWriteItems too, as the guides now say.
  • Expressions: more than 300 operators, redundant parentheses (((a = :v))), empty attribute names (in items, nested maps and ExpressionAttributeNames) and contains(a, a) are refused with DynamoDB's messages.
  • Messages: the hash key size message keeps DynamoDB's missing space ("limit of2048 bytes"). Updates over 400 KB say "Item size to update has exceeded the maximum allowed size", and empty index key values set by an update have the update form, with "binary" for binary values.
  • _core._check_expressions, which the test suite uses to check built expressions, now also validates update paths.

The stricter memory backend found a bug in dynamoxy itself: dynamoxy.condition(...) compiled with its own parentheses, so &, | and ~ sent (#a0 = :v0) AND ((#a1 > :v1)), which DynamoDB refuses as redundant parentheses (MiniStack accepts it). Hand-written conditions now compile without parentheses of their own, and &, | and ~ add none to a part that one pair encloses already (condition("(a OR b)") & ...).

Verified with Rust tests of the memory backend and the expression parser for each rule, with the captured messages and positions, and with Python tests of the condition builder and the expression checks. Old tests that encoded the accepted behaviour (two INSERTs of one item in a batch, deeply nested redundant parentheses) now check the refusal. make check passes, including the Python suites on the memory backend and MiniStack.

Refs #97: what no source settles is left, and described on the issue: the 255-byte limit of placeholder names, attribute names of 64 KB or more, attribute_type(a, b) with a path as the type, placeholders with invalid characters (#a-b), and a read-only transaction on a missing table.

Checklist

  • Tests cover the change (in-memory backend: these are its rules; the builder fix on both backends through the existing suites)
  • Docs updated (transactions, deployment and constraints guides, changelog)
  • make check passes locally (lint, types, clippy, consistency, tests)
  • Breaking change? No: what the memory backend now refuses, DynamoDB refuses

Worth confirming

  • Assumption: an UPDATE without SET or REMOVE is refused with "Statement wasn't well formed, can't be processed: UPDATE requires at least one SET or REMOVE clause". dynoxide-rs implements that wording but marks no capture for it.
  • Assumption: expressions over 300 operators get "Invalid Expression: The expression contains too many operators; operator count: 301". The limit and the counted operators come from DynamoDB's documentation, and the prefix is inferred from DynamoDB's other expression errors.

fctl session


Note

Medium risk. It makes the in-memory DynamoDB and the expression parser stricter (new refusals and messages, changed capacity numbers) and changes the expression text that dynamoxy.condition(...) and &, |, ~ send to every backend, so tests that passed before may now fail.

What it does. Brings the in-memory PartiQL and expression handling in line with what DynamoDB does, as captured by dynoxide-rs: mixed or duplicate PartiQL batches, RETURNING in ExecuteTransaction, duplicate key conditions, exists(), writes to an index, redundant parentheses, expressions over 300 operators and empty attribute names are refused, ALL_OLD failures return the stored item, and consumed capacity is adjusted. It also fixes a bug in dynamoxy itself: hand-written dynamoxy.condition(...) text no longer gets parentheses of its own, and And, Or and Not wrap a part only when one pair does not enclose all of it already, ignoring surrounding whitespace, so the generated expressions carry no redundant parentheses that DynamoDB refuses.

Condition compile change. RawCondition.compile no longer wraps its text and And, Or and Not use a new _grouped helper, so the expression strings sent to every backend for hand-written conditions change.

fctl review's first look at 698d4de · 17 files, +861 −131 · Review agent settings

fctl-sh Bot and others added 2 commits October 31, 2026 03:54
…d-written conditions get no redundant parentheses

The in-memory backend accepted PartiQL batches, transactions and
statements that DynamoDB refuses, ignored ALL_OLD in batches and
transactions, parsed no negative numbers after keywords, and reported
PartiQL capacity differently; expressions had no operator limit, no
refusal of redundant parentheses, empty attribute names or contains(a,
a), and a few messages differed. Rules and messages follow what
dynoxide-rs captured against DynamoDB.

Hand-written conditions combined with & and | compiled to redundant
parentheses, which DynamoDB refuses; they now compile without their own.

Refs #97

Co-authored-by: Carl Oscar Aaro <[email protected]>
@fctl-review

This comment has been minimized.

Comment thread python/dynamoxy/expressions.py Resolved
Also say in the guides that transactions double the table's write units
only, not the indexes'.

Co-authored-by: Carl Oscar Aaro <[email protected]>
@fctl-review

This comment has been minimized.

Comment thread python/dynamoxy/expressions.py Resolved
…espace get no second pair

Co-authored-by: Carl Oscar Aaro <[email protected]>
@fctl-sh

fctl-sh Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Stack of 10 pull requests, merged in this order with "Squash and merge":

  1. fix(models): numbers of union fields render as stored, and literals of plain enum members write #126 fix(models): numbers of union fields render as stored, and literals of plain enum members write
  2. fix(client): calls keep their middleware chain and deliver all their events #127 fix(client): calls keep their middleware chain and deliver all their events
  3. fix(pydantic): use_enum_values, forward references, RootModel fields and data-taking factories work #128 fix(pydantic): use_enum_values, forward references, RootModel fields and data-taking factories work
  4. fix(unique)!: upserts that race with creates, unique floats written back, and collections refused #129 fix(unique)!: upserts that race with creates, unique floats written back, and collections refused
  5. fix(transactions): commit() no longer raises after the transaction was applied #130 fix(transactions): commit() no longer raises after the transaction was applied
  6. fix(telemetry): records and metrics count PartiQL writes, throttles of failed calls, batch retries and rows #131 fix(telemetry): records and metrics count PartiQL writes, throttles of failed calls, batch retries and rows
  7. fix(testing): purge_expired, inject_fault(table=) and replayed transactions behave like DynamoDB #132 fix(testing): purge_expired, inject_fault(table=) and replayed transactions behave like DynamoDB
  8. fix(memory): queries refuse empty key values and start keys outside the key condition, and index keys have size limits #133 fix(memory): queries refuse empty key values and start keys outside the key condition, and index keys have size limits
  9. fix(binding): conversions take any mapping and refuse invalid wire values, and unknown table statuses are not active #134 fix(binding): conversions take any mapping and refuse invalid wire values, and unknown table statuses are not active
  10. fix(memory): PartiQL and expressions follow DynamoDB's rules, and hand-written conditions get no redundant parentheses #135 fix(memory): PartiQL and expressions follow DynamoDB's rules, and hand-written conditions get no redundant parentheses ← this pull request

@kalaspuff
kalaspuff merged commit a6555df into main Oct 31, 2026
22 checks passed
@kalaspuff
kalaspuff deleted the issues-stack/10-memory-parity branch October 31, 2026 04:11
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.

1 participant