Skip to content

1.19.1 — decimal precision

Latest

Choose a tag to compare

@vsdudakov vsdudakov released this 12 Oct 18:48
dce645b

Decimal precision fix: a Decimal with more than 28 decimal places, such as 1 / Decimal("162.35"), now binds instead of failing with invalid decimal "…": Failed to parse, and DecimalField rounds to its decimal_places before binding, as Tortoise did. Highlights:

Fixed

  • Decimals with more than 28 decimal places bind instead of failing. The engine's rust_decimal holds at most 28 places, even though NUMERIC accepts any scale. The binder now rounds the extra fractional digits half away from zero, as PostgreSQL does. Values that fit still bind exactly. A value whose integer part is too large, NaN or infinity still raises, and the error now gives the limit. (#31)
  • DecimalField rounds to decimal_places before binding, half away from zero, so model writes store the column's scale on every backend, including SQLite, which has no column scale of its own. (#31)

Behaviour note: decimal values passed for a DecimalField, filter values included, are now rounded to the field's scale. On SQLite the stored text carries the full scale (1.5 is written as 1.5000000000); the value compares equal.

Full details in CHANGELOG.md.