Skip to content

Fix REST API 500 error and schemathesis flaky test#941

Merged
juhoinkinen merged 4 commits into
mainfrom
fix-schemathesis-flaky-test
Jun 2, 2026
Merged

Fix REST API 500 error and schemathesis flaky test#941
juhoinkinen merged 4 commits into
mainfrom
fix-schemathesis-flaky-test

Conversation

@osma

@osma osma commented Jun 2, 2026

Copy link
Copy Markdown
Member

While working on #926 I had problems with a failing schemathesis test under GitHub Actions CI. Investigating it revealed two problems:

  1. The REST API can return 500 errors for untrained projects, even though the response should be 503 with a proper error message.
  2. The schemathesis test fails when the API returns a 503 response, even though it is correct and documented in the schema.

This PR fixes the two errors above.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes two issues encountered while testing untrained projects through the REST API: a NameError-induced 500 response when suggest_corpus/filter raised an AnnifException (because the success path executed after the except block referenced the unbound suggestion_results), and a flaky schemathesis test that flagged the legitimate 503 response as a server error.

Changes:

  • Move the suggestion_results_to_list(...) return inside the try block in _suggest, so the error path no longer falls through to code using an undefined variable.
  • Exclude the not_a_server_error schemathesis check in test_openapi_fuzzy so 5xx responses documented in the schema (e.g., 503) don't fail the fuzz test.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
annif/rest.py Returns the serialized result inside the try block, preventing a 500 when an AnnifException is caught.
tests/test_openapi.py Disables schemathesis' not_a_server_error check so documented 5xx responses don't cause spurious failures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.63%. Comparing base (826b35f) to head (45404a8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #941   +/-   ##
=======================================
  Coverage   99.63%   99.63%           
=======================================
  Files         103      103           
  Lines        8239     8241    +2     
=======================================
+ Hits         8209     8211    +2     
  Misses         30       30           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@osma osma requested a review from juhoinkinen June 2, 2026 09:17
@osma osma added the bug label Jun 2, 2026
@osma osma added this to the 1.5 milestone Jun 2, 2026
@osma osma self-assigned this Jun 2, 2026
@sonarqubecloud

sonarqubecloud Bot commented Jun 2, 2026

Copy link
Copy Markdown

@osma osma left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (can't approve this myself)

@juhoinkinen juhoinkinen merged commit 14b7443 into main Jun 2, 2026
15 checks passed
@juhoinkinen juhoinkinen deleted the fix-schemathesis-flaky-test branch June 2, 2026 11:23
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.

3 participants