Skip to content

An explicit codec makes an optional field required #77

Closed

Description

@fctl-sh

Priority: medium. A field given a codec (codec=, UseCodec(...)) is never wrapped as optional, so None is refused even when the annotation allows it and it is the default:

  • Attr[dict[str, Any] | None] = field(default=None, codec=JsonCodec()) fails on construction with its own default ("must not be None").
  • Attr[datetime | None] = field(default=None, codec=DateTimeCodec("iso_z")), the guides' way to give one field its own timestamp format, fails the same way.
  • Attr[Literal["on", "off", None]] fails too.
  • Pydantic Annotated[datetime | None, UseCodec(...)] = None validates, but create() fails with "is required".

Where: python/dynamoxy/schema.py (the codec of a field with codec= is used as given), python/dynamoxy/codecs.py (UseCodec ignores | None; Literal[..., None]).

Fix: wrap an explicit codec in OptionalCodec when the annotation includes None.

Found in a review of the library for bugs (fctl session); the fixes that fit in its ten pull requests are #61 to #65, #67 to #70 and #72.

Activity

  1. added
    bug
    on Oct 30, 2026
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