Repository navigation
Propagate hotel search errors instead of returning empty results - #285
Open
dex-the-ai wants to merge 1 commit into
Open
dex-the-ai wants to merge 1 commit into
dex-the-ai wants to merge 1 commit into
Conversation
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>
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
The hotel search seam in
CouchbaseClient(search_by_nameandfilterinapp/db.py) caught every exception, printed it, and carried on. The SDK runs a search request lazily, insiderows(). A missinghotel_searchindex, or any other search failure, therefore reached the API as200 []: the request looked like it succeeded but found no hotels. If the failure happened beforenames/hotelswas assigned, the method raisedUnboundLocalErrorinstead.The routers already turn exceptions into a
500with 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/filterwith 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 infilter.This is the same pattern that couchbase-examples/python-quickstart#156 fixed in the Flask quickstart.
Changes
app/db.py: removed the broadtry/exceptfromsearch_by_nameandfilter. Rows are now built with comprehensions, and docstrings note that errors propagate.app/routers/hotel.py: an empty or absent filter body passes{}todb.filter.app/tests/test_hotel_search_errors.py: 7 new offline tests. They use a fake scope whoserows()fails lazily, like the SDK does, plusapp.dependency_overrides[get_db], so they need no cluster.Validation
main: 5 failed, 2 passed (they reproduce the masking). On this branch: 7 passed.couchbase:enterprise-8.0.3cluster (data/index/query/fts services + travel-sample,hotel_searchindex at 917 docs),python -m pytest: 54 passed (47 existing + 7 new).mainGET /hotel/autocomplete?name=sea200 []500 QueryIndexNotFoundException…POST /hotel/filter {"city": …}200 []500 QueryIndexNotFoundException…POST /hotel/filter(no body)500 'NoneType' … model_dump200 []Successful search responses don't change.
🤖 Generated with Claude Code