kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Return 400 for malformed CSV log request dates and masterylog diff indexes

Open rtibbles opened this issue 2 weeks ago โ€ข 3 comments

๐Ÿ™‚ 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/ with selected_start_date set to "2020-01-01", "garbage", "2020-01-01 00:00:00(Mars/Base)" or 5 returns 500 (AttributeError, ValueError, UnknownTimeZoneError, TypeError). The serializer is a plain ModelSerializer (csv_log_request.py#L17), so it doesn't use Kolibri's DateTimeTzField mapping (serializers.py#L45). (facility admin)
  • GET /api/logger/masterylog/-1/diff/ raises AssertionError: Negative indexing is not supported., and /99999999999999999999/diff/ raises IntegrityError: 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 diff index 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 diff action 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.

rtibbles avatar Nov 15 '26 20:11 rtibbles

Hi! ๐Ÿ‘‹

This issue is available for contribution and supports self-assignment. Here's how to get started:

  • Comment /assign to 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.

learning-equality-bot avatar Nov 15 '26 21:11 learning-equality-bot

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.

singhmahipal avatar Nov 16 '26 14:11 singhmahipal

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.

learning-equality-bot avatar Nov 16 '26 14:11 learning-equality-bot