Skip to content

None and empty sets read back as the field's default #76

Closed

Description

@fctl-sh

Priority: high (needs a decision). A missing attribute decodes to the field's default, but None and empty sets are stored as missing attributes, so they read back as the default:

  • nickname: Attr[str | None] = field(default="anon") written as None reads back "anon".
  • roles: Attr[set[str]] = field(default_factory=lambda: {"member"}) written as set() reads back {"member"}, so a revoked role is granted again, and the next save() stores it. Pydantic models behave the same.

This contradicts docs/guides/modeling.md ("Empty sets are not stored ... and read back as empty sets").

Where: python/dynamoxy/schema.py, _decode fills missing attributes with spec.initial() before it considers None or empty sets.

Options: store NULL for None (and for empty sets) in fields whose default is not None (or not empty), which already decodes to None or an empty set: a stored format change (ADR), and key and index attributes must keep leaving the attribute out. Or refuse such declarations, or document that defaults apply to missing attributes in all cases.

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