fix(api): return 404/400 for malformed request input instead of 500#44
Merged
Conversation
Non-numeric execution and group ids now return 404 instead of raising DataError or ValueError on the raw int cast. Malformed or non-object facets JSON on the datasets list route returns 400 instead of an unhandled JSONDecodeError or AttributeError. The AFT routes no longer copy internal exception text into the response body, they log the detail and return a generic 500 message. Fixes the sanitize_float_value docstring, which claimed NaN and infinity became 0.0 when the code has always returned None. Also drops the warning log on every non-float series value, since None and int are legitimate series values, not something to warn about.
✅ Deploy Preview for climate-ref canceled.
|
lewisjared
marked this pull request as ready for review
July 20, 2026 06:04
📝 WalkthroughWalkthroughThe change adds explicit validation for dataset facets and execution identifiers, standardises AFT diagnostic error responses, and updates JSON sanitisation to use ChangesAPI input validation
AFT error containment
JSON sanitisation
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Malformed request input currently produces unhandled exceptions, so a crawler or a typo gets a 500 with a stack trace instead of a clean 4xx.
int(group_id)previously raisedValueError, and passing a raw string to an integer primary-key lookup raisesDataErroron Postgres.facetsJSON now returns 400 instead of raisingJSONDecodeErrororAttributeError. The facets-without-dataset_type branch returns 400 rather than an unhandledValueError.sanitize_float_valueno longer logs a warning for every legitimateNoneor int in a series, and its docstring now matches the code (NaN and infinity becomeNone, not0.0).Route signatures are unchanged, so the OpenAPI schema is byte-identical and no client regeneration is needed. Verified by diffing the generated schema against main.
Summary by CodeRabbit
Bug Fixes
nullin JSON output.Tests