Pydantic Decimal multiple_of: sharing exact counterexamples beyond the precision boundary
Teach and verify exact divisibility through independent arithmetic on the original decimal representation, rather than a rounded quotient.
Pydantic Decimal multiple_of: sharing exact counterexamples beyond the precision boundary
Validating a multiple is more than checking that a number parsed. Precision used in dividing a large Decimal can change remainder decisions, creating both false acceptance and false rejection. Compare exact application arithmetic with the validator's admission result to expose that asymmetry. [1, 2, 3]
What the primary source establishes
A report describes Decimal multiple_of rejecting a large even value while accepting a large odd value because it uses the ambient decimal context. It distinguishes quotient rounding from failure when the integer part exceeds the available precision. [1]
The handover decision
Validation and business owners should share even and odd fixtures on both sides of the precision boundary. Record false rejection separately from false acceptance. Keep decimal_text, divisor_text, exact_remainder, and validator_acceptance so an accepted model object does not become its own reference answer. [1, 3]
A reference defined before the output
The illustrative integer 12345678901234567890123456789 ends in 9, so division by 2 leaves remainder 1. An even control has remainder 0. A value admitted as a multiple must have independent exact remainder 0; remainder 1 is the counterexample. These fixtures define the arithmetic contract rather than reporting a new execution of Pydantic. [1, 3]
The scoped Truthound check
Truthound Core 3.3.2 can use ExpressionValidator to compare an independently calculated exact remainder with the admission state. The filter_expr operates on prepared table columns; do not assume the engine automatically performs arbitrary-precision Decimal remainder calculations. Keep arithmetic references independent of validation outcomes. [1, 2, 3]
Limits and alternative choices
This does not claim automatic arbitrary-precision Decimal arithmetic in Truthound; exact-remainder preparation is a preprocessing responsibility. Use an independent integer or sufficiently precise decimal calculation at the boundary and verify the supported release's fix status. If the business domain is demonstrably below the precision boundary, these large-value cases have lower immediate priority. [1, 3]
Application conditions
Calculate exact remainders independently from retained decimal text, and align them with the validator's acceptance records.
Alternatives
Use an independent integer or sufficiently precise decimal calculation at the boundary and verify the supported release's fix status.
Limitations
This does not claim automatic arbitrary-precision Decimal arithmetic in Truthound; exact-remainder preparation is a preprocessing responsibility.
Evidence
- Event checked
- Subject checked
- Modified
