Skip to content

fix: handle exception for API filter values that fail below tastypie - #11340

Merged
jennifer-richards merged 4 commits into
ietf-tools:mainfrom
rjsparks:guard_tastypie
Aug 7, 2026
Merged

fix: handle exception for API filter values that fail below tastypie#11340
jennifer-richards merged 4 commits into
ietf-tools:mainfrom
rjsparks:guard_tastypie

Conversation

@rjsparks

Copy link
Copy Markdown
Member

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.

rjsparks added 2 commits July 31, 2026 10:12
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

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.59%. Comparing base (3cce873) to head (d7e5cd2).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
ietf/api/__init__.py 78.57% 9 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread ietf/api/__init__.py
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"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess we can refactor this helper since we're on py3.12... for another day, though.

Comment thread ietf/api/tests.py Outdated
@jennifer-richards
jennifer-richards merged commit ea013e4 into ietf-tools:main Aug 7, 2026
9 checks passed
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants