Skip to content

[Bug]: /api/recommend crashes with 500 error when time is not low/medium/high #708

@sujitsingh8

Description

@sujitsingh8

What happened?

If you send /api/recommend a "time" value that isn't exactly low, medium, or high, the whole request crashes with a 500 Internal Server Error. The input validation only checks that "time" is non-empty — it never checks the value is valid. When a bad value reaches TIME_AVAILABILITY.index() in utils/recommender.py, it throws an uncaught ValueError. Expected a clean 400 with an error message; got a 500 crash instead.

Steps to reproduce

POST to /api/recommend with this body:

{
"skills": "python",
"level": "beginner",
"interest": "web",
"time": "flexible"
}

The server returns 500. The same crash happens with any value that isn't low/medium/high, including typos like "med" or "anytime".

Expected behaviour

A bad "time" value should be rejected with a 400 Bad Request and a clear message, the same way the other invalid inputs are already handled. It should not crash with a 500.

Area of the app affected

Recommendation results

Python version

3.14

Operating system

Windows 11

Relevant error output or logs

File "utils/recommender.py", line 72, in score_single_project
    time_availability_index = TIME_AVAILABILITY.index(time_availability.strip().lower())
ValueError: 'flexible' is not in list

Before submitting

  • I searched existing issues and this has not been reported before.
  • I can reproduce this bug consistently with the steps above.
  • I am running the latest version of the main branch.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions