Skip to content

fix(models): numbers of union fields render as stored, and literals of plain enum members write - #126

Merged
kalaspuff merged 2 commits into
mainfrom
issues-stack/1-codec-values
Oct 31, 2026
Merged

kalaspuff merged 2 commits into
mainfrom
issues-stack/1-codec-values

Conversation

@fctl-sh

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

Copy link
Copy Markdown
Contributor

What and why

Three of the smaller codec issues of #100 still reproduced on main (the fourth, update(M.tags.set(set())) and M.tags.remove() on a set field, was fixed by #113):

  • Key templates rendered Decimal values of union and Any fields as given. With amount: Attr[Decimal | str] and sk="PRICE#{amount}", Decimal("1.50") wrote PRICE#1.50, the instance read back rendered PRICE#1.5, and its save() raised "key changed". Templates now render a number of such a field as the field reads it back after DynamoDB normalized it, as they already did for Decimal fields (ADR 0013): Decimal("1.50") as 1.5, and 2.0 in an int | float field as 2.
  • Literal[Color.RED] with a member of a plain Enum passed validation and then failed to write ("cannot store a value of type Color"). The literal codec now stores the member's value (also in key templates and expressions) and reads back the member, as an Enum field does. A literal member whose value DynamoDB cannot store (a tuple) is a TypeError when the model is declared.
  • int fields raised OverflowError for Decimal("Infinity") and decimal.InvalidOperation for Decimal("sNaN"), instead of the validation error other values get.

Verified with unit tests of the codecs and of template rendering, which fail without the fix, and integration tests on the in-memory backend and MiniStack: a plain-enum literal in an attribute, a key template, an index key and a filter, and a Decimal | str sort key that a loaded instance saves back to the same item. make check passes.

Fixes #100

Checklist

  • Tests cover the change (in-memory backend and MiniStack)
  • Docs updated (modeling and single-table guides, changelog)
  • make check passes locally (lint, types, clippy, consistency, tests)
  • Breaking change? No: items keyed by a non-canonical number of a union field could not be saved back before; they keep their key and are moved as ADR 0013 describes

Worth confirming

  • Decision: a Literal of plain Enum members holds the member in instances (like an Enum field) and accepts only the member, not its bare value, when validating; members of (str, Enum) mixins stay plain values as before.
  • Assumption: lookups by a non-canonical number of a union field (get(amount=Decimal("1.50"))) now address PRICE#1.5, so they no longer find items written before with PRICE#1.50; such items could not be saved back before either.

fctl session


Note

Medium risk. It changes how number values of union and Any fields render into key templates and how Literal fields of plain Enum members are stored, which feeds keys and stored data, though only for fields that did not work or round-trip before.

What it does. Fixes three codec problems from #100. Key templates now render numbers of union and Any fields as DynamoDB reads them back (Decimal("1.50") as 1.5), so a loaded item's save() no longer reports a changed key. Literal fields of plain Enum members now store the member's value and read back the member, also inside lists, sets and maps, and int fields give a validation error for Decimal("Infinity") and Decimal("sNaN") instead of crashing.

Key rendering change. Lookups by a non-canonical number of a union field (get(amount=Decimal("1.50"))) now address PRICE#1.5, so items written earlier under PRICE#1.50 are no longer found and need the move that ADR 0013 describes.

fctl review's first look at da62fb3 · 9 files, +222 −18 · Review agent settings

…f plain enum members write

Key templates rendered Decimal values of union and Any fields as given
(PRICE#1.50 for Decimal("1.50")), while the instance read back rendered
PRICE#1.5, so its save() raised "key changed". They now render numbers
of such fields as the field decodes them after DynamoDB normalized them.

Literal[Color.RED] with a plain Enum member passed validation and
failed to write: the literal codec now stores the member's value and
reads back the member. IntCodec.validate() raised OverflowError and
InvalidOperation for infinite and signaling NaN Decimals instead of
a validation error.

Fixes #100

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

fctl-review Bot commented Oct 31, 2026

Copy link
Copy Markdown

fctl reviewed 69a466c and found 1 issue.

The template rendering and int validation changes look right. One gap: Literal[...] of plain Enum members still fails to write inside lists, sets and dicts.

On lines the diff doesn't show:

  • Literals of plain enum members still fail to write inside collections · Medium severity · python/dynamoxy/codecs.py line 742: LiteralCodec now has an encode that turns a plain Enum member into its value, but it is still in _ENCODED_UNCHANGED, so ListCodec, SetCodec and DictCodec copy their elements without calling it. With shades: Attr[list[Literal[Shade.DARK, Shade.LIGHT]]], to_item() keeps the Shade member and the write fails with "cannot store a value of type Shade"; the same happens for set[...] and dict[str, ...]. Removing LiteralCodec from the set fixes it, and a test with a list and a set of such literals would cover it.

Reviewed by fctl · Review agent settings

…mbers' values

Collections copied the elements of literal fields without encoding them,
so a list[Literal[Shade.DARK]] kept the member and the write failed.

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

fctl-sh Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in da62fb3: LiteralCodec now counts as encoding values unchanged only when it has no plain Enum members, so lists, sets and maps of such literals encode their elements (_encodes_unchanged in codecs.py). The integration test now writes, reads back and updates (append, add) a list, a set and a dict of them on both backends; it fails without the fix.

kalaspuff pushed a commit to hyperstructure/fctl that referenced this pull request Oct 31, 2026
…364)

## Summary

A review's findings on lines the diff doesn't show go in its summary
comment, not in threads of their own. A later review had no way to
resolve them: `fctl review threads` didn't list them, and `resolved`
took only thread ids. So a summary that held one never counted as
addressed, and stayed shown after its issue was fixed. Inline findings
already get resolved and their summaries hidden. kalaspuff/dynamoxy#126
shows the problem: the second review saw the fix but said "it has no
thread to resolve".

Now:

- `fctl review threads` lists each finding in an earlier summary's text,
with an id made of the summary's id and the finding's number there
(`IC_…#1`), its path and line. It shows as resolved once fixed, or once
the summary is hidden.
- `resolved` in `fctl review submit` takes those ids. The agent's
instructions, the review agent's AGENTS.md, `fctl review submit --help`
and the docs say so.
- The later review strikes through the finding's title in the summary
and adds a "Fixed in `sha`." line with the agent's note. It records the
finding's number in the summary's hidden note and counts it in the
"Addressed as of …" line. Once every issue in the summary is addressed,
it hides the summary as outdated, as for threads. If GitHub refuses the
edit, the summary stays shown.
- Findings in the text of summaries still shown count as still open,
like open threads. So a review with nothing new to report and such a
finding open gets a neutral check, not a passed one.
- New summaries' notes record how many findings their text holds
(`in_text`). Without that, a list the agent wrote in its own summary
text could pass for fctl's. Older summaries, like dynamoxy#126's, are
read from their list, up to the number of issues found.
- Restating an earlier summary no longer removes fctl's marks from the
text the agent wrote. A finding that quoted one could otherwise lose
text, or be merged with the next finding, and the wrong finding could be
struck through.

I verified it with unit tests in `fctl_domain::reviews`: listing, ids,
marking, standing and hiding, a summary in the exact older format, a
finding that quotes fctl's mark, and a list faked in the agent's text. I
also rendered a marked summary with GitHub's Markdown API to check that
the struck-through title and the "Fixed in" line show as intended. I
didn't run a review end to end against GitHub.

## Worth confirming

- **Decision:** A fixed finding stays in the summary with its title
struck through and a "Fixed in" line under it, rather than being
removed. This mirrors how fixed inline comments read.
- **Decision:** An open finding in a summary's text keeps a review's
check neutral until a later review finds it fixed or someone hides the
summary. People can't resolve it any other way, since it has no thread.
Pull requests whose old summaries hold such findings will see neutral
checks where they passed before, until those findings are marked fixed.

[fctl session](https://app.fctl.sh/s/ses_01M67W6EZG7WRWM4ZSF3V470X0)

<!-- FCTL_REVIEW_SUMMARY -->
---

> [!NOTE]
> **Low risk.** It changes how fctl's own review comments are restated
and counted, in the control plane's review posting code; a mistake would
show as a wrong review outcome or a summary left unmarked, not as lost
data.
>
> **What it does.** Findings that an earlier review put in its summary's
text, because their lines weren't in the diff, can now be resolved by a
later review through ids like `IC_…#1`, listed by `fctl review threads`.
The summary marks them fixed with a strike-through and a note, and hides
itself once everything in it is addressed. Since the last review it
keeps the agent's text whole when restating a summary, keeps a summary
shown when its edit failed, and counts unfixed in-text findings as still
open, so the check stays neutral. The CLI help, docs and the review
agent's prompt now name the new ids.
>
> **Review outcome.** A re-review with no new findings now ends neutral
instead of passing while a shown summary still holds unfixed findings in
its text.
>
> <sub>[fctl
review](https://app.fctl.sh/s/ses_01M67X1RFBXSXMWH1WR6GXP12F)'s first
look at
[`d239f0d`](d239f0d)
· 8 files, +624 −75 · [Review agent
settings](https://app.fctl.sh/p/fctl?tab=reviews)</sub>

<!-- /FCTL_REVIEW_SUMMARY -->

---------

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
@kalaspuff
kalaspuff added this pull request to stack #136 October 31, 2026 03:58
@fctl-sh

fctl-sh Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Stack of 10 pull requests, merged in this order with "Squash and merge":

  1. fix(models): numbers of union fields render as stored, and literals of plain enum members write #126 fix(models): numbers of union fields render as stored, and literals of plain enum members write ← this pull request
  2. fix(client): calls keep their middleware chain and deliver all their events #127 fix(client): calls keep their middleware chain and deliver all their events
  3. fix(pydantic): use_enum_values, forward references, RootModel fields and data-taking factories work #128 fix(pydantic): use_enum_values, forward references, RootModel fields and data-taking factories work
  4. fix(unique)!: upserts that race with creates, unique floats written back, and collections refused #129 fix(unique)!: upserts that race with creates, unique floats written back, and collections refused
  5. fix(transactions): commit() no longer raises after the transaction was applied #130 fix(transactions): commit() no longer raises after the transaction was applied
  6. fix(telemetry): records and metrics count PartiQL writes, throttles of failed calls, batch retries and rows #131 fix(telemetry): records and metrics count PartiQL writes, throttles of failed calls, batch retries and rows
  7. fix(testing): purge_expired, inject_fault(table=) and replayed transactions behave like DynamoDB #132 fix(testing): purge_expired, inject_fault(table=) and replayed transactions behave like DynamoDB
  8. fix(memory): queries refuse empty key values and start keys outside the key condition, and index keys have size limits #133 fix(memory): queries refuse empty key values and start keys outside the key condition, and index keys have size limits
  9. fix(binding): conversions take any mapping and refuse invalid wire values, and unknown table statuses are not active #134 fix(binding): conversions take any mapping and refuse invalid wire values, and unknown table statuses are not active
  10. fix(memory): PartiQL and expressions follow DynamoDB's rules, and hand-written conditions get no redundant parentheses #135 fix(memory): PartiQL and expressions follow DynamoDB's rules, and hand-written conditions get no redundant parentheses

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.

Smaller codec and update issues

1 participant