fix: handle exception for API filter values that fail below tastypie - #11340
Merged
Conversation
Filter values reach the ORM with very little validation, and some of them only fail after tastypie has stopped looking at them - either while the query is being built or once it runs. Those surfaced as unhandled exceptions. Add guards at both layers, in the ModelResource that every datatracker resource subclasses: dispatch() converts DataError into a bad request, covering values that are only rejected once the query reaches the database. Only DataError is treated this way, as the DBAPI error for a problem with the data in the query. OperationalError, ProgrammingError and InternalError indicate a broken database or a bug of ours, and still raise and report. The database's message is logged rather than returned, since it can quote the offending value into a response body that is not escaped.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11340 +/- ##
=======================================
Coverage 88.59% 88.59%
=======================================
Files 333 333
Lines 44669 44742 +73
=======================================
+ Hits 39575 39641 +66
- Misses 5094 5101 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jennifer-richards
previously approved these changes
Aug 4, 2026
| return f"{self._meta.api_name}:{self._meta.resource_name}:{':'.join(args)}:{smooshed}" | ||
|
|
||
| def _z_aware_fromisoformat(self, value: str) -> datetime.datetime: | ||
| """datetime.datetime.fromisoformat replacement that works with python < 3.11""" |
Member
There was a problem hiding this comment.
Guess we can refactor this helper since we're on py3.12... for another day, though.
jennifer-richards
approved these changes
Aug 7, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Filter values reach the ORM with very little validation, and some of them only fail after tastypie has stopped looking at them - either while the query is being built or once it runs. Those surfaced as unhandled exceptions.
Add guards at both layers, in the ModelResource that every datatracker resource subclasses:
dispatch() converts DataError into a bad request, covering values that are only rejected once the query reaches the database. Only DataError is treated this way, as the DBAPI error for a problem with the data in the query. OperationalError, ProgrammingError and InternalError indicate a broken database or a bug of ours, and still raise and report. The database's message is logged rather than returned, since it can quote the offending value into a response body that is
not escaped.