Commit 30b24a7
Keep the stored literal of a raw decimal zero (LMFDB#1010)
raw_json_dumps special-cased RealNumber, but psycodict does not hand back
a numeric that is exactly zero as one: numeric_converter returns an
LmfdbDecimalZero, an integer wrapper keeping the literal in .literal.
Such a value fell through to Json.prep, which sees a Sage integer and
emits 0, dropping the stored scale and, for -0.000, the sign, whether the
zero stood alone or sat inside a numeric[], a list or a dictionary. That
contradicted the format's promise that a numeric is the decimal Postgres
sent, copied verbatim.
The literal lookup moves into exact_decimal(), which handles the integer
wrapper alongside RealLiteral and RealNumber and validates the literal
against the JSON number syntax once, so nothing is rebuilt from a float
or an int. A numeric with no decimal point is still a Sage integer and is
unaffected; NaN and the infinities still fall back to psycodict's
extended encoding rather than emit an unparseable token.
test_api.py gains test_raw_json_dumps, calling the serializer directly so
the behaviour does not depend on finding a zero-valued row: 0.000, -0.000
and 1.250 come back verbatim, as do zeros nested in an array and in an
object, and each result is re-parsed as JSON. The exact strings are the
point, since Decimal("-0.000") == Decimal("0.000").
Verified: sage -python -m pytest lmfdb/api/test_api.py -> 8 passed;
pyflakes and ruff clean; /api/lfunc_lfunctions/?_format=raw&_fields=
mu_imag,analytic_normalization now gives [[0.0], 0] rather than [[0], 0].
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent 182d10b commit 30b24a7
2 files changed
Lines changed: 51 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
42 | 64 | | |
43 | 65 | | |
44 | 66 | | |
| |||
51 | 73 | | |
52 | 74 | | |
53 | 75 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
62 | 80 | | |
63 | 81 | | |
64 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
| |||
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
64 | 88 | | |
65 | 89 | | |
66 | 90 | | |
| |||
0 commit comments