Return 400 for malformed CSV log request dates and masterylog diff indexes
๐ 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.
Overview
Two logger endpoints return a 500 for malformed input: CSV log export requests with an unexpected date, and the mastery log diff action with a negative or oversized index. CSV log requests should return a 400, and the diff action a 404.
Complexity: Low Target branch: develop
Context
On develop at fe298f5449:
POST /api/logger/generatecsvlogrequest/withselected_start_dateset to"2020-01-01","garbage","2020-01-01 00:00:00(Mars/Base)"or5returns 500 (AttributeError,ValueError,UnknownTimeZoneError,TypeError). The serializer is a plainModelSerializer(csv_log_request.py#L17), so it doesn't use Kolibri'sDateTimeTzFieldmapping (serializers.py#L45). (facility admin)GET /api/logger/masterylog/-1/diff/raisesAssertionError: Negative indexing is not supported., and/99999999999999999999/diff/raisesIntegrityError: datatype mismatch.mastery_log.py#L90-L97. (learner)
The Change
- The CSV log request serializer should parse its date fields the way Kolibri's other timestamp fields are parsed.
- The
diffindex should be validated as a non-negative integer.
Acceptance Criteria
- [ ] Each CSV log request under Context returns 400.
- [ ]
GET /api/logger/masterylog/-1/diff/and/99999999999999999999/diff/return 404, as/abc/diff/does. - [ ] CSV log exports created from the Facility > Data page work as before.
- [ ] The
diffaction returns the same results as before for indexes from 0 up. - [ ] Tests cover each request under Context.
AI usage
I had Claude Code sweep Kolibri's API code for unvalidated request input and reproduce each 500 with a test. I chose the fix and the split into sub-issues. Claude Code drafted the issue to the pattern of #15838.
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.
I'd like to take this issue.
I have read the Contributing guidelines, including the section on Using generative AI.
I reproduced both cases on current develop:
- POST /api/logger/generatecsvlogrequest/ with selected_start_date="garbage" โ 500 (ValueError). The serializer in csv_log_request.py is a plain ModelSerializer and doesn't use Kolibri's DateTimeTzField mapping.
- GET /api/logger/masterylog/-1/diff/ โ AssertionError ("Negative indexing is not supported"); /99999999999999999999/diff/ โ IntegrityError.
Plan: make the CSV log serializer validate dates like other Kolibri timestamp fields (โ 400), and validate the diff index as a non-negative integer (โ 404, same as /abc/diff/).
/assign
Disclosure: I used an AI assistant to help draft this comment; I reviewed the source and ran the reproduction myself.
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.