Skip to content

Handle malformed progress in learning-path analytics - #1901

Open
ionfwsrijan wants to merge 1 commit into
komalharshita:mainfrom
ionfwsrijan:fix/1861-analytics-malformed-progress
Open

Handle malformed progress in learning-path analytics#1901
ionfwsrijan wants to merge 1 commit into
komalharshita:mainfrom
ionfwsrijan:fix/1861-analytics-malformed-progress

Conversation

@ionfwsrijan

Copy link
Copy Markdown
Contributor

Problem

GET /api/learning-path/<path_id>/analytics returns HTTP 500 when stored progress contains a malformed value. create_path/update_path accept arbitrary client JSON, so a non-dict progress value (e.g. a string or list) makes stats.get(...) raise AttributeError, which the except (ValueError, TypeError) clause does not catch. A non-dict progress container also breaks progress.items().

Fix

In src/routes/main_routes.py analytics handler:

  • Coerce a non-dict progress container to {} so .items() cannot crash.
  • Add AttributeError to the caught exceptions so a malformed per-project stats value is skipped instead of 500-ing.

Files changed

  • src/routes/main_routes.py
  • tests/test_learning_path.py

Testing

  • New TestPathAnalyticsRoute tests: analytics returns 200 for a string stats value, a list progress container, and a valid payload (previously 500 for the first two).
  • tests/test_learning_path.py: 51 passed.

Closes #1861

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

@ionfwsrijan is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /api/learning-path/<id>/analytics returns 500 on malformed stored progress - AttributeError not caught

1 participant