Context
The GET /search endpoint has an off-by-one error in its pagination slicing. When the number of matching results equals or exceeds the limit, it returns one fewer result than it should.
Steps to reproduce
- Create 5 profiles with usernames starting with "a" (alice, alex, anna, amy, adam).
- Search with
GET /search?q=a&limit=3.
- The
total field correctly shows 5, but results contains only 2 items instead of 3.
You can also reproduce with a test:
def test_search_pagination():
# (add 5 profiles with "a" in username)
response = client.get("/search?q=a&limit=3")
assert len(response.json()["results"]) == 3 # FAILS: returns 2
Expected behavior
With limit=3, the endpoint should return up to 3 matching results.
Actual behavior
With limit=3, the endpoint returns only 2 results because the slice uses offset + limit - 1 instead of offset + limit.
Files
app/main.py -- the search_profiles function, the return statement with the slice
Acceptance criteria
Suggested approach
- Open
app/main.py and find the search_profiles function.
- Find the line:
results[offset : offset + limit - 1]
- Change it to:
results[offset : offset + limit]
- Run
pytest tests/test_search.py -v.
Context
The
GET /searchendpoint has an off-by-one error in its pagination slicing. When the number of matching results equals or exceeds thelimit, it returns one fewer result than it should.Steps to reproduce
GET /search?q=a&limit=3.totalfield correctly shows 5, butresultscontains only 2 items instead of 3.You can also reproduce with a test:
Expected behavior
With
limit=3, the endpoint should return up to 3 matching results.Actual behavior
With
limit=3, the endpoint returns only 2 results because the slice usesoffset + limit - 1instead ofoffset + limit.Files
app/main.py-- thesearch_profilesfunction, the return statement with the sliceAcceptance criteria
GET /search?q=...&limit=Nreturns up to N results (not N-1)totalfield remains unchanged (full count, not sliced count)Suggested approach
app/main.pyand find thesearch_profilesfunction.results[offset : offset + limit - 1]results[offset : offset + limit]pytest tests/test_search.py -v.