Commit cf6557a
authored
GET /organizations/{id}/sums returns 500 with `{"detail": "Generic error"}`
for any organization that has no emissions logged in the requested
period. From the dashboard side this makes new or quiet organizations
look broken.
Tracing through `get_organization_detailed_sums`, the joins are outer
joins but the timestamp filter on `Emission` ends up in the WHERE clause
and so cancels them out for empty organizations. The query returns
nothing, `.first()` returns `None`, and the router hands `None` back to
FastAPI which trips the global exception handler and masks the real
shape of the response.
I kept the SQL alone and handled the empty case in the usecase, where
`get_one_organization` is already available for the metadata. When the
sums query comes back as `None` we look the organization up and return
a zero-valued `OrganizationReport`. Rebuilding the joins would be a
larger, more invasive change than what the issue asks for.
Added a parallel unit test in
`tests/api/usecase/organization/test_organization_detailed_sums.py`
that mocks both repository methods so it runs without a database. On
the unfixed code it fails on the first attribute access on `None`; on
the fixed code it passes. The existing happy-path test is unchanged.
Closes #693
1 parent edd49c8 commit cf6557a
2 files changed
Lines changed: 50 additions & 1 deletion
File tree
- carbonserver
- carbonserver/api/usecases/organization
- tests/api/usecase/organization
Lines changed: 24 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
0 commit comments