Skip to content

Let hotel search errors reach the API layer instead of masking them - #156

Merged
nithishr merged 1 commit into
mainfrom
architecture-audit/python-quickstart-2026w47
Nov 19, 2026
Merged

nithishr merged 1 commit into
mainfrom
architecture-audit/python-quickstart-2026w47

Conversation

@dex-the-ai

Copy link
Copy Markdown
Contributor

What

CouchbaseClient.search_by_name and CouchbaseClient.filter (src/db.py) no longer catch and swallow search errors. Errors now reach the hotel routes, which already turn exceptions into a 500. Those routes now use hotel_ns.abort(500, ...) so the error message isn't mangled by @marshal_with.

Why

Error handling for the hotel search endpoints was split between two layers, and the inner layer hid failures:

Failure main This PR
hotel_search index missing/broken (the SDK raises while streaming rows) HTTP 200 [], which looks like "no hotels found" HTTP 500 {"message": "Unexpected error: QueryIndexNotFoundException(...)"}
Error raised before the result list exists UnboundLocalError: cannot access local variable 'names', which hides the real Couchbase error The original CouchbaseException goes to the route and comes back as a 500

Both rows were observed against a live Couchbase 8.0.3 cluster: start the app, delete the hotel_search index, then call /api/v1/hotel/autocomplete and /api/v1/hotel/filter.

Architecturally, the CouchbaseClient adapter becomes a plain pass-through for search, the same as its KV and query methods. The decision about what an error means for the HTTP response now lives only in the route module.

Validation

  • python -m pytest tests/test_db_search_errors.py: 5 passed. These are new cluster-free unit tests that stub the scope, covering an eager failure and a lazy failure during row iteration. With main's db.py restored, 4 of the 5 fail.
  • Full suite against local couchbase:enterprise-8.0.3 (travel-sample, data/index/query/fts), with the app started the same way as in CI: 52 passed (47 existing integration tests and 5 new).
  • Happy-path responses are unchanged, and the existing hotel integration tests pass as before.

🤖 Generated with Claude Code

CouchbaseClient.search_by_name and filter caught every exception, printed
it, and fell through. A missing/broken hotel_search index (the SDK raises
while streaming rows) therefore returned HTTP 200 [] and looked like "no
hotels"; an error raised before the result list existed crashed with
UnboundLocalError instead of the real Couchbase error.

The client adapter now lets search errors propagate, so error handling
lives in one place: the hotel routes, which already map exceptions to
500. Those routes use hotel_ns.abort so the message is not mangled by
marshal_with.

Adds cluster-free unit tests for both failure modes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nithishr
nithishr merged commit 739f04e into main Nov 19, 2026
4 checks passed
@nithishr
nithishr deleted the architecture-audit/python-quickstart-2026w47 branch November 19, 2026 17:44
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.

2 participants