Skip to content

Propagate hotel search errors instead of returning empty results - #285

Open
dex-the-ai wants to merge 1 commit into
mainfrom
architecture-audit/python-quickstart-fastapi-2026w47
Open

dex-the-ai wants to merge 1 commit into
mainfrom
architecture-audit/python-quickstart-fastapi-2026w47

Conversation

@dex-the-ai

Copy link
Copy Markdown
Contributor

Summary

The hotel search seam in CouchbaseClient (search_by_name and filter in app/db.py) caught every exception, printed it, and carried on. The SDK runs a search request lazily, inside rows(). A missing hotel_search index, or any other search failure, therefore reached the API as 200 []: the request looked like it succeeded but found no hotels. If the failure happened before names/hotels was assigned, the method raised UnboundLocalError instead.

The routers already turn exceptions into a 500 with the error detail, so the client now lets search errors propagate. The adapter keeps one job: building the FTS request and mapping its rows. The router keeps HTTP error mapping.

A related fix in the same route: POST /api/v1/hotel/filter with no body used to return a 500 ('NoneType' object has no attribute 'model_dump'). It now returns [], which matches the existing "no filter fields means empty list" path in filter.

This is the same pattern that couchbase-examples/python-quickstart#156 fixed in the Flask quickstart.

Changes

  • app/db.py: removed the broad try/except from search_by_name and filter. Rows are now built with comprehensions, and docstrings note that errors propagate.
  • app/routers/hotel.py: an empty or absent filter body passes {} to db.filter.
  • app/tests/test_hotel_search_errors.py: 7 new offline tests. They use a fake scope whose rows() fails lazily, like the SDK does, plus app.dependency_overrides[get_db], so they need no cluster.

Validation

  • New tests on main: 5 failed, 2 passed (they reproduce the masking). On this branch: 7 passed.
  • Full suite against a local couchbase:enterprise-8.0.3 cluster (data/index/query/fts services + travel-sample, hotel_search index at 917 docs), python -m pytest: 54 passed (47 existing + 7 new).
  • Live check with the index name pointed at a missing index:
Request main this PR
GET /hotel/autocomplete?name=sea 200 [] 500 QueryIndexNotFoundException…
POST /hotel/filter {"city": …} 200 [] 500 QueryIndexNotFoundException…
POST /hotel/filter (no body) 500 'NoneType' … model_dump 200 []

Successful search responses don't change.

🤖 Generated with Claude Code

CouchbaseClient.search_by_name/filter wrapped the search in a broad
try/except that only printed the error. The SDK runs the search lazily
in rows(), so a missing hotel_search index (or any search failure) came
back as 200 []. An earlier failure raised UnboundLocalError instead.
The router already maps exceptions to 500, so the client now lets
them propagate.

Also: POST /hotel/filter with no body now returns [] instead of a 500
AttributeError on None.model_dump().

Adds offline tests (fake scope + dependency override) for the
search seam. They need no cluster.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dex-the-ai
dex-the-ai requested a review from nithishr November 19, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant