You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
None and empty sets read back as the field's default #76
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