Skip to content

fix(models): expressions on inherited fields use the subclass's datetime_format - #111

Merged
kalaspuff merged 7 commits into
mainfrom
fctl/57-https-github-com-kalaspuff-dynamoxy-issu
Oct 31, 2026
Merged

kalaspuff merged 7 commits into
mainfrom
fctl/57-https-github-com-kalaspuff-dynamoxy-issu

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Native models reused the path object of the class that declared a field, so the fields a subclass inherits (Article.seen_at, declared by an abstract Timestamped) encoded expression values with the declaring class's schema. With Article(Timestamped, datetime_format="iso_z"), put() stored ...Z, but filter(Article.seen_at == at) and key and write conditions rendered ...+00:00 and matched nothing (with an epoch format they rendered text where numbers are stored), and update(Article.seen_at.set(at)) stored ...+00:00 among ...Z values. The same cause made transactions take the declaring class as the model of an update by key: tx.update(Article.key(...), Article.seen_at.set(at)) raised TypeError: Timestamped is not stored in a table. And assigning or comparing an inherited field failed when the base class's schema cannot be built on its own, for example when its key template names a field of the subclass.

Every native model and document class now gets paths of its own for the fields it inherits, bound to its own schema, as pydantic models already did. The paths of the base class keep the base's format. The modeling guide and AGENT_GUIDE now say to build conditions and updates from the class you read or write.

Verified with new tests that fail without the fix: an integration test on the in-memory backend and MiniStack (put, a key condition with an inclusive bound, a filter and a conditional update), a transaction's update by key on both backends, instance methods given the paths of sibling classes (native and pydantic, both backends), and unit tests of the encoded values, a deeper subclass, error messages and a base class whose schema cannot be built. A pydantic test keeps both kinds of models equal. make check passes, and the affected test modules pass on Python 3.12 too.

Fixes #79

Checklist

  • Tests cover the change (in-memory backend and MiniStack)
  • Docs updated (modeling guide, AGENT_GUIDE.md, changelog)
  • make check passes locally (lint, types, clippy, consistency, tests; no Rust change)
  • Breaking change? No

Worth confirming

  • Decision: the paths of a base class keep its format, also in requests for a subclass that stores another one: client.model(Article).scan().filter(Timestamped.seen_at == at) still compares ...+00:00. The issue asked for subclass paths, and making a base class's paths follow the repository's model would mean encoding values when a request is built rather than when the expression is. The guides say to use the class you read or write instead.
  • Decision: since a subclass's paths belong to it, the instance methods add(), increment() and decrement() refuse the path of a sibling class, as they already did for pydantic models. With Page and Post both inheriting views, post.increment(Page.views) raises TypeError: Page.views is not a field of Post: use Post.views, where native models accepted the shared path before; the changelog says so. The class's own path and the base class's still work.

fctl session


Note

Medium risk. It changes how every native model and document class collects its fields: each subclass now gets path objects of its own for inherited fields, so Subclass.field is a different object than before, and instance methods now refuse a sibling class's path.

What it does. Fixes expressions on fields that a subclass inherits: conditions, filters and updates built from Article.seen_at used the datetime_format of the abstract class that declared the field, not of the subclass that stores it. A subclass now gets paths of its own for the fields it inherits, bound to its own schema, which also fixes transactions picking the declaring abstract class as the model of an update by key and the TypeError when a base class's key template names a subclass field. Tests cover native and pydantic models on the in-memory backend and MiniStack, and the modeling guide, agent guide and changelog are updated.

Base-class and sibling paths. Paths taken from a base class still encode values in the base's format, so conditions must be built from the class being read or written. Instance methods such as increment() now refuse the path of a sibling class: post.increment(Page.views) raises TypeError naming Post.views, where the shared path was accepted before.

fctl review's first look at 3cf2ea3 · 11 files, +213 −9 · Review agent settings

fctl-sh Bot and others added 3 commits October 30, 2026 23:29
…ime_format

A native model that inherits a field reused the path object of the
class that declared it, so `Article.seen_at` encoded values with the
schema of the abstract `Timestamped`. When the subclass sets another
`datetime_format`, filters, key and write conditions compared text in
the base class's format with what the subclass stores and found
nothing, and updates stored values in the base class's format.
Transactions took the declaring class as the model of updates by key
(`Timestamped is not stored in a table`), and assigning or comparing
an inherited field failed when the base class's schema could not be
built on its own (a key template naming a field of the subclass).

Every native model and document class now gets paths of its own for
the fields it inherits, as pydantic models already did. The paths of
the base class keep the base's format.

Fixes #79

Co-authored-by: Carl Oscar Aaro <[email protected]>
…com-kalaspuff-dynamoxy-issu

Both sides added a Fixed entry to CHANGELOG.md and tests at the end of
tests/unit/test_pydantic.py: keep both, main's first.

Co-authored-by: Carl Oscar Aaro <[email protected]>
…com-kalaspuff-dynamoxy-issu

Both sides added a Fixed entry to CHANGELOG.md: keep both, main's first.

Co-authored-by: Carl Oscar Aaro <[email protected]>
@fctl-review

This comment has been minimized.

Comment thread python/dynamoxy/models.py Resolved
fctl-sh Bot and others added 4 commits October 30, 2026 23:54
Since each class has paths of its own, the instance methods add(),
increment() and decrement() refuse the path of a sibling class that
inherits the same field, as they already did for pydantic models:
with Page and Post both inheriting views, post.increment(Page.views)
raises TypeError. Pin that with a test on native and pydantic models,
name the attribute to use in the message ("use Post.views"), and say
it in the changelog.

Co-authored-by: Carl Oscar Aaro <[email protected]>
…com-kalaspuff-dynamoxy-issu

Both sides added a Fixed entry to CHANGELOG.md (keep both, main's first)
and a test model import to tests/integration/test_transactions.py
(import both Article and Player).

Co-authored-by: Carl Oscar Aaro <[email protected]>
…com-kalaspuff-dynamoxy-issu

Both sides added a Fixed entry to CHANGELOG.md: keep both, main's first.

Co-authored-by: Carl Oscar Aaro <[email protected]>
…com-kalaspuff-dynamoxy-issu

Both sides added a Fixed entry to CHANGELOG.md: keep both, main's first.

Co-authored-by: Carl Oscar Aaro <[email protected]>
@kalaspuff
kalaspuff merged commit 1142f44 into main Oct 31, 2026
22 checks passed
@kalaspuff
kalaspuff deleted the fctl/57-https-github-com-kalaspuff-dynamoxy-issu branch October 31, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inherited fields use the declaring class's datetime_format in expressions

1 participant