Skip to content

bug: skill-progression endpoints 500 with 'Object of type SkillDifficulty is not JSON serializable' #1868

Description

@ionfwsrijan

Summary

POST /api/skill-progression/record and GET /api/skill-progression/user/<user_id> 500 with TypeError: Object of type SkillDifficulty is not JSON serializable. record_skill_completion stores the SkillDifficulty enum member in the returned dict, and the routes hand that dict to jsonify / json.dumps, which cannot serialize a plain Enum.

Evidence

src/utils/skill_progression.py:196:

skill_data = self.user_skills[user_id][skill_name]
skill_data["difficulty"] = difficulty          # <-- the SkillDifficulty enum, not .value/.name

SkillDifficulty is a plain Enum (BEGINNER = 1, ..., EXPERT = 4), so it is not JSON-serializable by the stdlib encoder.

Reproduced (Python 3.13):

json.dumps({"difficulty": SkillDifficulty.EXPERT, "completed_at": "…",
            "assessment_score": None, "progression_history": []})
TypeError: Object of type SkillDifficulty is not JSON serializable

Routes that return this dict:

  • src/routes/main_routes.py:613-626record returns jsonify({"skill_data": skill_data}) (line 620-626) → 500 after a successful record.
  • src/routes/main_routes.py:637-644get_user_progression returns skills (which contains the enum) → 500.

(Only progression_history entries store difficulty.name — a string — so the feature is one field away from working.)

Impact

  • Recording a skill completion fails with HTTP 500 even though the record itself succeeded in memory.
  • Retrieving a user's skill progression always returns 500 once any skill is recorded.

Suggested Fix

Store difficulty.value (or .name) at skill_progression.py:196, or serialize enums explicitly (e.g. SkillDifficulty.__members__ mapping / default=str). Add a test asserting json.dumps(skill_data) succeeds after record_skill_completion.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions