Repository navigation
fix(models): members of mixin enums are the plain values of str and int fields - #69
Merged
kalaspuff merged 3 commits intoOct 30, 2026
Conversation
This comment has been minimized.
This comment has been minimized.
This was referenced Oct 30, 2026
Contributor
Author
|
Stack of 5 open pull requests (from a pass over the library for bugs; #61 to #65 are merged already), merged in this order with "Squash and merge":
The findings that are not fixed here are filed as issues (see the next comment on #72). |
This was referenced Oct 30, 2026
This comment has been minimized.
This comment has been minimized.
…nt fields A member of a `(str, Enum)` or `(int, Enum)`, the mixins of code written before StrEnum and IntEnum, passed the validation of a str, int or Literal field and was kept as it was. The item stored its value (`"book"`), but key templates, derived index keys and unique guards rendered its str(), which is "Kind.BOOK" for such enums. The item got the key `KIND#Kind.BOOK#s1`: reads by the value missed it, the loaded instance rendered `KIND#book#s1` so its save() raised "key changed", and a unique value written as "book" was not taken. The str and int codecs now return the plain str or int a subclass holds, and the Literal codec the literal a value matches, so instances, templates, guards and conditions use what DynamoDB stores. Co-authored-by: Carl Oscar Aaro <[email protected]>
…s too `Literal[Kind.BOOK, Kind.CD]` with `class Kind(str, Enum)`: the Literal codec returned the declared member, whose str() is "Kind.BOOK", so templates and guards rendered it again, now also for items read back. It returns the plain str or int of the literal a value matches. Co-authored-by: Carl Oscar Aaro <[email protected]>
kalaspuff
force-pushed
the
fixes-stack/08-enum-values
branch
from
October 30, 2026 21:40
89ee47a to
df4871a
Compare
… too `Attr[str | int]` (the union the usage guide suggests for changing a field's type) kept a `(str, Enum)` member as it was, so templates rendered `K#Kind.BOOK`. The union codec returns the plain value as well. Co-authored-by: Carl Oscar Aaro <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
A member of a
(str, Enum)or(int, Enum)passed the validation of astr,int,Literalor union (str | int) field and stayed an enum member. These are the mixins of code written beforeenum.StrEnumandIntEnum. DynamoDB stored its value ("book"), but key templates, derived index keys and unique guards rendered it withstr(), and for such enums that gives"Kind.BOOK". Withpk="KIND#{kind}#{sku}"andProduct(kind=Kind.BOOK, sku="s1", ...):KIND#Kind.BOOK#s1while itskindattribute held"book", soget(kind="book", sku="s1")returnedNone.KIND#book#s1, so itssave()raisedValueError(the key changed since it was loaded).CODE#Code.ONE, and the unique guard oflabel=Kind.BOOKwas..._unique#Product#label#Kind.BOOK, so a second item withlabel="book"was accepted.StrEnum,IntEnumand pydantic models were not affected. Thestr,intand union codecs now return the plainstrorinta subclass holds (str.__str__,int.__int__), and theLiteralcodec returns the plain value of the literal a value matches, also for literals that are members of such an enum (Literal[Kind.BOOK, Kind.CD]). So instances, templates, guards and conditions all use what DynamoDB stores. Field paths and key lookups validate before encoding, which covers update actions, conditions and reads by key too.Verified with a new integration test on the in-memory backend and MiniStack (the key, an index key with a
Literalfield, aLiteralof enum members and a union field, the unique guard, a read by value andsave()of the item read back), and with the whole suite, ruff, pyrefly and the consistency checks.Checklist
make checkpasses locally (lint, types, consistency, tests; no Rust change)Worth confirming
strorintfield now holds the plain value even when given aStrEnumorIntEnummember (user.name = Kind.BOOKreads back as"book"), as an item read back always did; fields typed with the enum keep their members.KIND#Kind.BOOK#s1) are not migrated: nothing uses the library yet, so this pull request leaves them out.fctl session
Note
Medium risk. It changes what
validatereturns forstr,int,Literalandstr | intfields, which feeds the keys, templates and unique guards of every model, though only when a value is a subclass ofstrorintsuch as a mixin enum member.What it does. Members of
(str, Enum)and(int, Enum)mixin enums used to be stored as their value but rendered asKind.BOOKin keys, templates and unique guards, so items got keys that reads by the value missed andsave()of a loaded item failed. Thestr,int,Literaland union codecs now turn such a value into the plainstrorintit holds, so what a model holds, renders and stores agree. A test covers creation, a read, a save and an index query, and the changelog and modeling guide are updated.Stored keys. Items that were already written with the
Kind.BOOKform of a key before this fix are not migrated, and reads by the plain value still miss them.fctl review's first look at
c13b53f· 4 files, +89 −10 · Review agent settings