Skip to content

fix: return empty election lists with HTTP 200 - #192

Closed
Gambit-Checkmate wants to merge 1 commit into
CSSS:mainfrom
Gambit-Checkmate:fix/empty-election-list
Closed

Gambit-Checkmate wants to merge 1 commit into
CSSS:mainfrom
Gambit-Checkmate:fix/empty-election-list

Conversation

@Gambit-Checkmate

Copy link
Copy Markdown

Summary

Closes #189.

  • Return HTTP 200 with [] when GET /election finds no elections, both with and without with_nominees=true.
  • Remove the collection endpoint's obsolete 404 response from OpenAPI and describe its empty-list response.
  • Add HTTP-level unit tests for the default/false/true nominee query, the OpenAPI responses, and the unchanged 404 for a missing individual election.

Both CRUD list functions already return sequences, so removing the empty-result exceptions lets the existing serialization produce an empty array. Database queries, authorization, and individual-election lookup behavior are unchanged.

Verification

Windows, Python 3.13.15, locked development/test dependencies. The local environment additionally uses tzdata because Windows does not provide the system timezone database; no dependency or lockfile changes are included.

  • Before the fix: the new tests produced 4 failures (the three empty collection requests and its OpenAPI response) and 1 pass (missing individual election).
  • python -m pytest tests/unit -q: 61 passed (existing baseline: 56 passed).
  • ruff check .: passed.
  • ruff format --check src/elections/urls.py tests/unit/test_elections.py: passed.
  • git diff --check: passed.

The new tests exercise the FastAPI router through HTTPX's ASGI transport with mocked database dependencies. PostgreSQL-backed integration tests were not run; no real database was connected or modified.

Opened as a draft following the project's PR checklist. Prepared with AI assistance.

@jbriones1 jbriones1 closed this Sep 19, 2026
@jbriones1 jbriones1 mentioned this pull request Sep 20, 2026
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.

Return status of GET elections incorrect

2 participants