Skip to content

fix(binding): conversions take any mapping and refuse invalid wire values, and unknown table statuses are not active - #134

Merged
kalaspuff merged 3 commits into
issues-stack/8-memory-query-validationfrom
issues-stack/9-binding-conversions
Oct 31, 2026
Merged

kalaspuff merged 3 commits into
issues-stack/8-memory-query-validationfrom
issues-stack/9-binding-conversions

Conversation

@fctl-sh

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

Copy link
Copy Markdown
Contributor

What and why

The smaller binding and AWS adapter issues of #101:

  • Mappings: the stub declares Mapping for expression_attribute_names/expression_attribute_values, request_items, tags, _check_expressions/_apply_update's names/values, from_wire and value_from_wire, but the binding took only dicts: a MappingProxyType or UserDict raised TypeError. The binding now takes any collections.abc.Mapping there, as the stub says. PartiQL parameters given as a str (a Sequence too) raise TypeError instead of being split into characters, and the stub types them as a list or tuple.
  • Typed wire format: the binding now refuses invalid input with ValidationError, using DynamoDB's wording where it has one.
    • base64 is strict: padding only at the end and at most two =, so "====", "A===" and "AA==AAAA" no longer decode to zero bytes.
    • {"NULL": false} is refused ("Null attribute value types must have the value of true"), and so are empty sets ("An string set may not be empty").
    • {"N": 5}, {"BOOL": 1}, a str for L, SS, NS or BS, and non-str names raise ValidationError instead of TypeError.
  • Python values the binding could not write: a lone surrogate (from json.loads('"\\ud800"')) raised UnicodeEncodeError, and an int of more than 4,300 digits raised Python's int-to-str ValueError. Both are now a ValidationError, and ints beyond DynamoDB's range are refused before they are written out. An int subclass with its own __str__ is written as its number, using int.__repr__, also above 2**63.
  • Ready is iterable: yield from call.__await__() in types.coroutine code raised TypeError for in-memory calls; the awaitable now has __iter__, like an asyncio.Future.
  • Wake-up writes: the event loop bridge ignored every error of its 1-byte write. After a failure other than a full buffer (ENOBUFS, ENOMEM), no byte was pending and later completions never woke the loop. Such a write is now retried with a short backoff until a byte is pending, and interrupted writes are retried at once.
  • Unknown table statuses: the AWS adapter read table statuses it does not know, such as REPLICATION_NOT_AUTHORIZED or ones added later, as ACTIVE, and unknown global index statuses as no status, so wait_for_table took such tables for ready. The table status enum now has REPLICATION_NOT_AUTHORIZED and UNKNOWN, and the index status enum UNKNOWN; waiters do not take these for ready. A response without any status reads as before.

Verified with Python tests of the native module (wire format, mappings, invalid text and numbers, int subclasses, a generator coroutine, mapping arguments of client calls, str parameters) and a Rust test of the table and index status mapping, each failing without the fix. make check passes. The wake-up retry has no test: the binding crate has no Rust test harness, and the failure cannot be provoked from Python. It was found and fixed by reading.

Fixes #101

Checklist

  • Tests cover the change (native module; the AWS status mapping in Rust)
  • Docs updated (low-level access guide, TableDescription.status, _core.pyi, changelog)
  • make check passes locally (lint, types, clippy, consistency, tests)
  • Breaking change? No: what is now refused was invalid input that read as something else or raised another exception

Worth confirming

  • Decision: the binding accepts any mapping, as the stub declares, rather than the stub being narrowed to dict.
  • Decision: a table status the adapter does not know reads as "UNKNOWN" rather than its own name, since the status is a fixed enum in the core.

fctl session


Note

Medium risk. It makes the native conversions of from_wire/to_wire and the client's call arguments stricter, and changes how the event loop is woken and how unknown table and index statuses are read, so inputs that used to pass can now raise.

What it does. The native module's functions now accept any mapping (such as MappingProxyType or UserDict) where the type stubs promise one, and PartiQL parameters given as a str raise TypeError instead of being split into characters. The typed wire format (from_wire, value_from_wire) now refuses invalid input with ValidationError: malformed base64, {"NULL": false}, empty sets, wrongly typed N, S and BOOL values, non-list containers, lone surrogates and numbers out of DynamoDB's range. It also lets in-memory calls be awaited with yield from, retries a failed event-loop wake-up write, and reads a table or index status that the AWS SDK adds later as UNKNOWN instead of ACTIVE, so wait_for_table keeps waiting. Tests cover the new conversions and error messages, and the changelog and low-level access guide say what changed.

Stricter wire parsing. from_wire and value_from_wire now take only a list or tuple for L, SS, NS and BS and raise ValidationError for input they used to read leniently, so callers passing sets or other iterables there will see errors.

fctl review's first look at 7734f16 · 12 files, +403 −85 · Review agent settings

…lues, and unknown table statuses are not active

The binding took only dicts where its stubs promise mappings, split a
str of PartiQL parameters into characters, read invalid typed values
("====" base64, {"NULL": false}, {"SS": []}) and raised TypeError,
UnicodeEncodeError or ValueError instead of ValidationError for others.
In-memory awaitables lacked __iter__, a failed wake-up write could
leave later calls undelivered, and the AWS adapter read table statuses
it does not know as ACTIVE.

Fixes #101

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

This comment has been minimized.

@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 ← this pull request
  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

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.

Binding and AWS adapter: smaller conversion, stub and status issues

1 participant