Skip to content

Fix toggle-favourite HTTPException handling and add DB helper + tests. #issue 1179#1

Open
Cairo09 wants to merge 2 commits into
mainfrom
codex/update-toggle_favourite-to-handle-httpexception
Open

Fix toggle-favourite HTTPException handling and add DB helper + tests. #issue 1179#1
Cairo09 wants to merge 2 commits into
mainfrom
codex/update-toggle_favourite-to-handle-httpexception

Conversation

@Cairo09
Copy link
Copy Markdown
Owner

@Cairo09 Cairo09 commented Feb 17, 2026

Motivation

  • Prevent the toggle_favourite() route from converting intended HTTPException responses (e.g. 404) into generic 500 errors.
  • Avoid an expensive full-table fetch after toggling the favourite flag by retrieving only the updated isFavourite value.
  • Provide API-level tests to assert correct 200 and 404 behaviors for the toggle endpoint.

Description

  • Updated backend/app/routes/images.py to explicitly re-raise HTTPException and handle unexpected errors with a generic except Exception returning 500.
  • Replaced the full-table lookup in toggle_favourite() with a call to the new helper db_get_image_favourite_status(image_id) and used that value in the response.
  • Added db_get_image_favourite_status() and switched db_toggle_image_favourite_status() to use the shared _connect() helper in backend/app/database/images.py.
  • Added focused API tests in backend/tests/test_images.py that mock DB calls to cover a successful toggle and the unknown-image 404 case.

Testing

  • Ran python -m py_compile backend/app/routes/images.py backend/app/database/images.py backend/tests/test_images.py which succeeded.
  • Executed pytest backend/tests/test_images.py in this environment and it failed during test bootstrap due to an external system library import error (cv2 -> libGL.so.1 missing), preventing full test execution.
  • The new tests are unit-level and mock DB functions, and they should pass in a normal CI/test environment where the test bootstrap imports resolve successfully.

Codex Task

Remove docstring for db_get_image_favourite_status function.
@Cairo09 Cairo09 changed the title Fix toggle-favourite HTTPException handling and add DB helper + tests Fix toggle-favourite HTTPException handling and add DB helper + tests. #issue 1179 Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant