Content node tree endpoints return 500 for invalid depth and next__gt query parameters
๐ Looking for an issue? Welcome! This issue is open for contribution. If this is the first time youโre requesting an issue, please:
- Read Contributing guidelines carefully. Pay extra attention to Using generative AI. Pull requests and comments that donโt follow the guidelines wonโt be answered.
- Confirm that youโve read the guidelines in your comment.
Summary
Requesting a content node tree with an invalid depth or next__gt query parameter returns 500 instead of 400.
TreeQueryMixin.validate_and_return_params (kolibri/core/content/viewsets/contentnode/tree.py) raises Django's ValidationError for out-of-range or unparseable values, but DRF's exception handler does not convert a Django ValidationError into a 400 response, so the request dies with an unhandled exception. A next__gt above SQLite's 64-bit integer range passes validation and raises OverflowError in the query.
Steps to reproduce
GET any of /api/content/contentnode_tree/<id>/, /api/public/v2/contentnode_tree/<id>/ or /api/content/contentnodeprogress/<id>/tree/ with any of:
?depth=abc,?depth=1.5,?depth=0,?depth=3(valid depth is 1 or 2)?next__gt=abc,?next__gt=1.5,?next__gt=0,?next__gt=-1,?next__gt=99999999999999999999(must be a positive integer if specified)
Expected
400 naming the invalid field (depth or next__gt), and the current behavior for valid values.
Actual
500 (Internal Server Error logged). Verified: every invalid value above returns 500, while ?depth=1 returns 200.
Possible fix
Replace validate_and_return_params with a Serializer that validates request.query_params, as #15838's Guidance describes for query parameters that don't filter: depth = IntegerField(min_value=1, max_value=2, default=2) and next__gt = IntegerField(min_value=1, max_value=2147483647, required=False). The maximum is the safe range of lft's PositiveIntegerField.
๐ Thanks for opening this issue! @rtibblesbot will check it against the code and comment with its findings.
What happens next:
- The
community-issue-reviewlabel stays on until the review comment is posted. - The comment identifies the files, lines, or commits examined so you can follow the reasoning and respond if you disagree.
- If the check confirms the issue, @rtibblesbot may also correct the title and description. GitHub preserves the edit history, so the original text remains available.
- @rtibblesbot's comments are LLM-generated, so please evaluate them critically.
A maintainer decides what happens next. This check does not close the issue.
Verdict: claim holds
Evidence: kolibri/core/content/viewsets/contentnode/tree.py:4, :45, :55 on develop at fe298f5449
TreeQueryMixin.validate_and_return_paramsraisesdjango.core.exceptions.ValidationErrorfor a baddepthornext__gt; DRF's handler (wrapped bycustom_exception_handler) does not convert it, so the request 500s.- A test-client run at fe298f5449 returned 500 for all eight invalid values listed in the issue, and 200 for
?depth=1, on each route that uses the mixin:/api/content/contentnode_tree/<id>//api/public/v2/contentnode_tree/<id>//api/content/contentnodeprogress/<id>/tree/
- The URL in the issue,
/api/content/contentnode/<id>/tree/, does not exist:ContentNodeViewsethas notreeaction. The steps now list the three routes above. - Not a duplicate: #15826 (
random'smax_results) and #15829 (notifications'limit) are other endpoints.
Changes
- Steps to reproduce: replaced
/api/content/contentnode/<id>/tree/with the three routes that useTreeQueryMixin. The original route does not exist (ContentNodeViewsethas notreeaction), and all three return 500 for every listed value. - Title: "endpoint returns" โ "endpoints return", because the steps now name three routes.
Written by rtibblesbot, an LLM-based coding agent.
Hi! ๐
This issue is available for contribution and supports self-assignment. Here's how to get started:
- Comment
/assignto assign yourself to this issue - You can have up to 2 issues assigned at a time across all community repos
- Dropping an issue has a 7-day cooldown before the slot opens up
- Link your pull request to this issue when you submit it
๐ Read the Contributing guidelines before starting.
Are you preparing for Google Summer of Code? See our GSoC guidelines.
/assign
Hi! ๐
You've been assigned to this issue. Here's what to do next:
- Read the issue description carefully and make sure you understand the requirements
- Link your pull request to this issue when you submit it
- If you can no longer work on this, unassign yourself so others can pick it up
Good luck! ๐
Are you preparing for Google Summer of Code? See our GSoC guidelines.
Updated the expected behavior and possible fix to follow #15838: validate depth and next__gt with a Serializer on request.query_params, so the 400 names the field. Also added ?next__gt=99999999999999999999, which passes the current check and returns 500 from an SQLite OverflowError.