fix: add title query param endpoint to resolve HTTP 422 (#1075)#1647
Open
Bhavy12-cell wants to merge 1 commit into
Open
fix: add title query param endpoint to resolve HTTP 422 (#1075)#1647Bhavy12-cell wants to merge 1 commit into
Bhavy12-cell wants to merge 1 commit into
Conversation
🎉 Welcome to Hybrid Recommender, @Bhavy12-cell!Thank you for your first pull request! Here's what happens next:
⏱️ Please respond to any review comments within 48 hours. 📖 Resources: Happy contributing! 🚀 |
|
🎉 Welcome to Hybrid Recommender, @Bhavy12-cell! This is your first contribution here! Labels added: PR Description Checklist: What happens next:
⏱️ Please respond to review comments within 48 hours. |
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
Fixes #1075
Problem
The frontend (
frontend/app.js) makes recommendation requests using atitlequery parameter:GET /api/recommend?title=<item_name>
However, the backend router (
backend/routers/recommend.py) had no endpoint that accepted atitlequery parameter. FastAPI was rejecting every such request with:HTTP 422 Unprocessable Entity
{"detail": [{"loc": ["query", "item_title"], "msg": "field required", "type": "value_error.missing"}]}
This forced the frontend to fall back to the path-based route
/api/recommend/{item_title}on every single request, causing unnecessary double round-trips.Root Cause
backend/routers/recommend.pywas missing an endpoint for item-based recommendations via query parameter. No route accepted?title=...so FastAPI returned 422 on the first request every time.Fix
Added a new GET
/api/recommendations/itemendpoint to the router that explicitly acceptstitleas a required query parameter using FastAPI'sQuery():@router.get("/item")
def get_item_recommendations(
title: str = Query(..., min_length=1),
top_n: int = Query(default=10, ge=1, le=100),
):
Now the frontend's first request succeeds without any fallback needed.
Files Changed
backend/routers/recommend.py— added/itemendpoint withtitlequery param supportTesting