← Back to bug list · View issue #164 in MantisBT
Reported by: Nour aboulhosn on 2026-08-04T08:58:41+01:00
Assigned to: Claude
Resolved by: Claude on 2026-08-04T13:19:18+01:00
Severity: major
Priority: high
Reproducibility: have not tried
Category: General
Description: The amount field validates the raw input for being greater than zero and for being numeric — `0` and negatives return a clean “How much? must be more than zero.” and non-numeric input returns “How much? must be a number.” — but the value is only rounded to two decimal places *after* that validation has already passed. A positive sub-cent value such as `0.001`, `0.004`, or `1e-4` therefore slips past the `> 0` check, rounds down to `0.00`, and then fails at the storage step (an unhandled database/constraint exception), returning a 500 error page to the user. The identical crash occurs on the refunds endpoint (`/invoices/{id}/refunds`) with a `0.001` refund amount, which confirms both paths share the same money-parsing and insert logic. This must be resolved by moving the “greater than zero” check so it runs *after* the amount has been normalized and rounded rather than before it: the rule should be applied to the final value that will actually be stored, so that any input which rounds to `0.00` is rejected inline with the same friendly “must be more than zero” message instead of ever reaching the database. Correctly functioning, entering `0.001` should either round to a valid non-zero stored amount or be refused on the form, and under no circumstance should a well-formed numeric input produce an unhandled 500; as a defence in depth the insert itself should be wrapped so that any constraint violation degrades into a validation message rather than a server crash.
Steps to Reproduce: 1. Go to Add an expense, type `0.001` in the amount field, pick any category, and save. 2. Observe an HTTP 500 “Something went wrong” page instead of a validation message (compare: entering `0` or `-5` shows a clean “must be more than zero”). 3. Repeat on a paid invoice's Record a refund form with a refund amount of `0.001` — the same 500 occurs.
Resolution: WHAT 0.001 passed the “must be more than zero” check, rounded to 0.00, and then hit the database CHECK constraint as an unhandled exception — a 500 page from a form that had just accepted the input. Identical crash on /invoices/{id}/refunds.
WHERE - app/classes/Core/Validator.php — money() replaces numeric()+positive()+moneyMax() - app/controllers/ExpenseController.php, RecurringController.php, InvoiceController.php
WHY This is entirely an ORDERING bug, and the ticket diagnosed it correctly. positive() ran against the RAW input while the rounding happened later at the insert. A rule about a stored value has to be asked of the stored value.
FIX money() rounds FIRST and judges after: shape → round to scale → “> 0” → ceiling. Anything that rounds to 0.00 is refused inline with the ordinary “How much? must be more than zero.” The refunds endpoint now shares the same rule rather than only sharing the parsing, which is why it crashed identically.
VERIFIED (real HTTP posts) — 0.001 and 0.004 on an expense and 0.001 on a refund all return the validation message; no 500, no row written.
Regression test: tests/Core/MoneyRuleTest.php ::testAnAmountThatRoundsToNothingIsRefusedNotCrashed asserts the raw value is positive AND rounds to zero, so the test fails if the ordering is ever restored.
0.001 passed the “must be more than zero” check, rounded to 0.00, and then hit the database CHECK constraint as an unhandled exception — a 500 page from a form that had just accepted the input. Identical crash on /invoices/{id}/refunds.
WHERE - app/classes/Core/Validator.php — money() replaces numeric()+positive()+moneyMax() - app/controllers/ExpenseController.php, RecurringController.php, InvoiceController.php
WHY This is entirely an ORDERING bug, and the ticket diagnosed it correctly. positive() ran against the RAW input while the rounding happened later at the insert. A rule about a stored value has to be asked of the stored value.
FIX money() rounds FIRST and judges after: shape → round to scale → “> 0” → ceiling. Anything that rounds to 0.00 is refused inline with the ordinary “How much? must be more than zero.” The refunds endpoint now shares the same rule rather than only sharing the parsing, which is why it crashed identically.
VERIFIED (real HTTP posts) — 0.001 and 0.004 on an expense and 0.001 on a refund all return the validation message; no 500, no row written.
Regression test: tests/Core/MoneyRuleTest.php ::testAnAmountThatRoundsToNothingIsRefusedNotCrashed asserts the raw value is positive AND rounds to zero, so the test fails if the ordering is ever restored.
| Date | User | Field | Change |
|---|---|---|---|
| 2026-08-04T08:58:41+01:00 | Nour aboulhosn | issue-new | New Issue |
| 2026-08-04T13:19:16+01:00 | Claude | note-added | Note Added: 0000122 |
| 2026-08-04T13:19:17+01:00 | Claude | tag-added | Tag Attached: done-by-claude |
| 2026-08-04T13:19:18+01:00 | Claude | Assigned To | ⇒ Claudine |
| 2026-08-04T13:19:18+01:00 | Claude | Status | new ⇒ resolved |
| 2026-08-04T13:19:18+01:00 | Claude | Resolution | open ⇒ fixed |
Synced automatically from MantisBT issue #164.