Skip to content

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

Closed

Description

@fctl-sh

Priority: low. 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) puts the Python value into the expression unencoded, so every request with it fails before any I/O:

class Bird(dynamoxy.Model, table="birds"):
    bird_id: Attr[str] = dynamoxy.partition_key()
    seen: Attr[list[datetime]] = dynamoxy.field(default_factory=list)


await birds.scan().filter(Bird.seen.contains(moment)).count()
# ValidationError: :v0: cannot store a value of type datetime in DynamoDB; use str, int, ...

Lists and sets of str, numbers and bytes work only because their values need no encoding, and Bird.seen[0] == moment encodes the value as stored.

Where: python/dynamoxy/attributes.py, FieldPath.contains. It builds a Path whose encoder is the element codec, and Path.contains then takes that codec's element() again, which is None for these types, so the value is neither validated nor encoded.

Fix: validate and encode the value with self.spec.codec.element() directly, as FieldPath._value does for comparisons, and test contains() on lists and sets of datetimes, UUIDs and documents on both backends.

Found while fixing #79 (fctl session).

Activity

  1. added
    bug
    on Oct 30, 2026
  2. added a commit that references this issue on Oct 31, 2026
    ac304f2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions