fix: return all validation errors from /api/recommend - #250
Closed
Tranquil666 wants to merge 2 commits into
Closed
Conversation
Previously only errors[0] was returned, forcing users to fix and resubmit one field at a time. The response key is now "errors" (list). Also moves `import os` to module level in download_code().
|
Someone 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. |
komalharshita
requested changes
May 19, 2026
komalharshita
left a comment
Owner
There was a problem hiding this comment.
The API validation improvement itself looks good conceptually, and returning all validation errors is a better user experience overall.
However, the CI checks are currently failing, so this PR cannot be safely merged yet.
Since the response structure changed from:
{ "error": "..." }to:
{ "errors": [...] }the failing checks may indicate broken tests or frontend compatibility issues related to the updated API response format.
Please:
- resolve all failing CI checks
- verify frontend/client compatibility with the new response structure
- update/add tests if necessary
Once CI passes and compatibility is confirmed, this can be re-reviewed.
test_recommend_api_missing_field was asserting the old "error" string key — updated to assert "errors" list key and verify it is non-empty. static/script.js was reading data.error (string) from /api/recommend — updated to read data.errors (list) and join all messages for display so the user sees every validation problem at once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary [required]
The
/api/recommendendpoint collected all validation errors viavalidate_recommendation_inputs()but only ever returnederrors[0]to the client. This forced users to fix one field, resubmit, discover the next error, and repeat — a frustrating loop when multiple fields are invalid at once. This PR returns the fullerrorslist so every problem is surfaced in a single response.A second minor fix in the same file moves
import osfrom inside thedownload_code()function body to the module-level imports, which is required by PEP 8 (E402) and the project's code style rules.Related Issue [required]
Closes #
Type of Change [required]
What Was Changed [required]
routes/main_routes.py{"errors": errors}(list) instead of{"error": errors[0]}(string); moveimport osto module-levelCHANGELOG.md### Fixedas required by CONTRIBUTING.md for user-facing changesHow to Test This PR [required]
git checkout fix/return-all-validation-errorspip install -r requirements.txtpython app.py"errors"key with all four error messages, not just one{"projects": [...]}response is unchangedpython tests/test_basic.pyExpected test output:
Test Results [required]
Self-Review Checklist [required]
fix/return-all-validation-errorspython tests/test_basic.pyand all 29 tests passflake8 routes/main_routes.pylocally and there are no errorsprint()orconsole.log()debug statementsNotes for Reviewer
The response key changes from
"error"(string) to"errors"(list). If any frontend JavaScript currently readsresponse.error, it will need to switch toresponse.errorsorresponse.errors[0]. Worth checkingstatic/JS before merging.Pre-existing flake8 violations exist in
starter_code/andutils/but are unrelated to this PR —routes/main_routes.pyis clean.