Skip to content

Models: subclass instances, keys stored in non-canonical text, and nested attributes of newer versions #99

Closed

Description

@fctl-sh

Priority: low (partly design).

  • Subclass instances are stored as the base model (repository.py, writes accept any isinstance match and encode with the repository's schema): client.model(User).create(Admin(level=9)) stores _type: "User" and drops level; client.model(User).get(...) of an Admin item returns a User, whose save() rewrites _type, so Admin.query no longer finds it. A document field typed as a base class drops a subclass instance's extra fields. Refuse instances of other models, or write them through their own repository.
  • Keys stored in non-canonical text make loaded instances address another key (codecs.py accepts any parseable text; repository.py renders the key from the instance's values): a UUID key stored upper-case by another writer reads back, but the instance renders the lower-case key, so delete() deletes nothing, refresh() raises ItemNotFoundError and save() raises "key changed". A date key stored as 20260102 renders as 2026-01-02. ADR 0015 says keys of loaded instances are the stored keys.
  • Saves by an older version of an application erase nested attributes a newer one added (_with_undeclared keeps top-level attributes only): a new top-level attribute survives, address.zip_code does not. ADR 0014 covers top-level attributes only, but AGENT_GUIDE.md says older versions "do not erase what a newer one wrote".

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.

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