Skip to content

fix(expressions): contains() encodes members of lists and sets as the field stores them - #116

Merged
kalaspuff merged 1 commit into
issues-stack/1-pydantic-inherited-fieldsfrom
issues-stack/2-contains-element-codecs
Oct 31, 2026
Merged

kalaspuff merged 1 commit into
issues-stack/1-pydantic-inherited-fieldsfrom
issues-stack/2-contains-element-codecs

Conversation

@fctl-sh

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

Copy link
Copy Markdown
Contributor

What and why

contains() on a model field that holds a list or set of values with a codec (list[datetime], list[date], set[UUID], list[timedelta], a list of plain Enum members or of documents) put the Python value into the expression unencoded, so every filter or condition with it raised ValidationError: cannot store a value of type datetime in DynamoDB before any request. FieldPath.contains built a Path whose encoder was the element codec, and Path.contains then took that codec's element() again, which is None for these types. Lists and sets of strings, numbers and bytes only worked because their values need no encoding.

contains() now validates and encodes the value with the element codec, the way comparisons use the field's codec, so a value of the wrong type raises ValidationError naming the field when the condition is built. Fields without elements (strings, bytes, JSON) still take a substring as given. The usage guide says so.

Verified with an integration test on the in-memory backend and MiniStack that filters on lists and sets of datetimes, dates, UUIDs, timedeltas, plain enums, documents and strings, a substring, and an update condition, and that fails without the fix; and a unit test of the encoded value for a pydantic model. make check passes.

Fixes #112

Checklist

  • Tests cover the change (in-memory backend and MiniStack)
  • Docs updated (AGENT_GUIDE.md, changelog)
  • make check passes locally (lint, types, clippy, consistency, tests; no Rust change)
  • Breaking change? No

fctl session


Note

Low risk. It changes how contains() builds its condition for list and set model fields, in one method of the Python expression layer, and it was failing outright for the affected element types before.

What it does. contains() on a model field holding a list or set of values with a codec (datetimes, dates, UUIDs, timedeltas, plain enums, documents) now validates and encodes the value with the element codec, so filters and conditions on those fields no longer raise ValidationError before any request. Fields without elements (strings, bytes) still take a substring as given. Tests cover the in-memory backend, MiniStack and a pydantic model, and the usage guide and changelog are updated.

Stricter checks. A value of the wrong type passed to contains() on a list or set field, such as a str for a list[int], now raises ValidationError naming the field when the condition is built, where it used to be sent unchecked.

fctl review's first look at 93c980d · 5 files, +97 −9 · Review agent settings

… field stores them

FieldPath.contains built a Path whose encoder was the element codec,
and Path.contains took that codec's element() again, which is None for
datetimes, dates, UUIDs, timedeltas, plain enums and documents. The
value went into the expression unencoded, and every request with it
failed with "cannot store a value of type datetime" before any I/O.

contains() now validates and encodes the value with the element codec,
as comparisons do with the field's codec.

Fixes #112

Co-authored-by: Carl Oscar Aaro <[email protected]>
@kalaspuff
kalaspuff added this pull request to stack #124 October 31, 2026 01:30
@kalaspuff
kalaspuff merged commit ac304f2 into main Oct 31, 2026
22 checks passed
@kalaspuff
kalaspuff deleted the issues-stack/2-contains-element-codecs branch October 31, 2026 01:34
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.

contains() on lists and sets of datetimes, UUIDs or documents raises ValidationError

1 participant