validate_metadata leaks decimal.InvalidOperation on bad fiat_amount #38
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
core.validation.validate_metadata()is meant to wrap parse failures offiat_amountinto aValidationError, but theexceptclause doesn't catch the actual exception raised byDecimal(). The rawdecimal.InvalidOperationpropagates out, breaking the contract.Reproduce
Raises
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]instead ofValidationError("Invalid fiat_amount: not-a-number").Where
core/validation.py:282-289:decimal.InvalidOperationinherits fromArithmeticError, notValueErrororTypeError, so the catch silently fails.Fix
Add
decimal.InvalidOperationto the catch tuple:Surfaced from
The pure-function unit tests in
tests/test_unit.py::test_validate_metadata_fiat_amount_invalid_decimal_raises— the test was asserting the documented behaviour (ValidationErrorfor bad input), and that's what surfaced the gap.Scope
One-line fix in
core/validation.py. Worth grepping the rest ofvalidation.pyandcrud.pyfor similartry: Decimal(...) except ValueErrorpatterns that have the same hole.