Skip to content

Commit 6d38625

Browse files
committed
docs: state plainly that Python 1.0.x float decimals have no restoring option (#454)
1 parent 2f9f367 commit 6d38625

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ _Fixes #454 and #455. A bug-fix release: no vocabulary or `metamodelVersion` cha
3131
Java and Kotlin** write a decimal as a JSON number again (`12.50`), and a value object's null
3232
member as `null` with its key present: the 1.0.x output. **Python and TypeScript** write a
3333
decimal as their standard string, which keeps its scale (`"12.50"`). That is a change from
34-
1.1.1's `"12.5"`.
34+
1.1.1's `"12.5"`. **Python adopters coming from 1.0.x:** 1.0.x routers returned plain dicts,
35+
and FastAPI's encoder wrote a `Decimal` as a float (`12.5`), losing digits past a double's
36+
precision. From 1.1.2 a decimal is Pydantic's string, `str(Decimal)` (`"12.50"`), so a client
37+
that read a number now reads a string. There is no float option, by decision: a float that
38+
loses precision is not the Python-normal form, and Pydantic's string is.
3539
**To keep 1.1.0's output** in every port, declare
3640
`"wire": { "decimals": "string", "nullMembers": "omit" }` and regenerate. `nullMembers` also
3741
takes `"emit"`, which writes every declared member of a value object, `null` when unset,

‎docs/features/migrations/upgrading-1.0-to-1.1.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ setting each port writes its language's standard JSON:
158158
- **Python:** a decimal is the string Pydantic writes for a `Decimal`, `str(value)` (`"12.50"`).
159159
1.0.x routers returned plain dicts, and FastAPI's encoder turned a `Decimal` into a float
160160
(`12.5`, losing digits past a double's precision). A client that read a number now reads a
161-
string. No setting restores the float, because it loses digits.
161+
string. There is no float option, by decision: a float that loses precision is not the
162+
Python-normal form, and Pydantic's `str(Decimal)` is. Update a client that parsed the number to
163+
parse the string (`"decimals": "string"` gives the canonical `"12.5"` instead).
162164

163165
To have every port write one form, which suits clients in several languages or a browser that
164166
must read decimals exactly, declare the form 1.1.0 wrote and regenerate:

0 commit comments

Comments
 (0)