Skip to content

fix: add title query param endpoint to resolve HTTP 422 (#1075)#1647

Open
Bhavy12-cell wants to merge 1 commit into
leonagoel:mainfrom
Bhavy12-cell:fix/query-param-mismatch
Open

fix: add title query param endpoint to resolve HTTP 422 (#1075)#1647
Bhavy12-cell wants to merge 1 commit into
leonagoel:mainfrom
Bhavy12-cell:fix/query-param-mismatch

Conversation

@Bhavy12-cell

Copy link
Copy Markdown

Summary

Fixes #1075

Problem

The frontend (frontend/app.js) makes recommendation requests using a title query parameter:
GET /api/recommend?title=<item_name>

However, the backend router (backend/routers/recommend.py) had no endpoint that accepted a title query 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.py was 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/item endpoint to the router that explicitly accepts title as a required query parameter using FastAPI's Query():

@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 /item endpoint with title query param support

Testing

  • GET /api/recommendations/item?title=Headphones → 200 OK
  • GET /api/recommendations/item (no title) → 422 with clear error message
  • All existing endpoints unchanged and working

@github-actions

Copy link
Copy Markdown

🎉 Welcome to Hybrid Recommender, @Bhavy12-cell!

Thank you for your first pull request! Here's what happens next:

Step What Who
1 CI runs lint + smoke test 🤖 Automated
2 Code review 👤 @leonagoel
3 mentor:leonagoel label added 👤 Mentor
4 gssoc:approved label added 👤 Mentor
5 Auto-merge triggered 🤖 Automated
6 Points on leaderboard at 4 AM IST 🏆 GSSoC

⏱️ Please respond to any review comments within 48 hours.

📖 Resources:

Happy contributing! 🚀

@github-actions

Copy link
Copy Markdown

🎉 Welcome to Hybrid Recommender, @Bhavy12-cell! This is your first contribution here!

Labels added: gssoc:approved | mentor:leonagoel | status:review-needed

PR Description Checklist:

NO - What changed section
NO - Why section
NO - How to test section
YES - Related issue linked

⚠️ Some required sections are missing. Please update your PR description.

What happens next:

  1. @leonagoel will review your changes
  2. CI checks must pass
  3. Once approved, this PR will be auto-merged

⏱️ Please respond to review comments within 48 hours.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: HTTP 422 Validation Failures Due to Query Parameter Mismatch

1 participant