Skip to content

Finalize FastAPI refactor: fix 5 runtime bugs and add API test suite - #203

Draft
alvarolopez with Copilot wants to merge 12 commits into
v3-fastapifrom
copilot/refactor-api-to-use-flask
Draft

Finalize FastAPI refactor: fix 5 runtime bugs and add API test suite#203
alvarolopez with Copilot wants to merge 12 commits into
v3-fastapifrom
copilot/refactor-api-to-use-flask

Conversation

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown

The aiohttp→FastAPI migration had several bugs preventing the API from running at all. This fixes them and adds 38 endpoint tests to validate the implementation.

Bug fixes

  • Model never instantiated (model/v2/__init__.py): stevedore returns a class; was passing it unwrapped to ModelWrapper → every method call raised TypeError: missing 1 required positional argument: 'self'. Added ().

  • Dead async code in warm() (model/v2/wrapper.py): method was async def and referenced self._loop/self._executor/self._workers that were never defined. Made synchronous, removed unused asyncio/functools imports.

  • get_root() crashes on disabled docs (api/__init__.py, api/v2/__init__.py): APP.docs_url[1:] raised AttributeError when docs are disabled (url is None). Also get_root did await get_v2_version(request) on a plain def — made get_v2_version async.

  • JSONResponse missing content= kwarg (api/v2/predict.py): JSONResponse(ret) passes the dict as a positional arg, not content.

  • Form/File fields broken under Pydantic v2 + FastAPI Depends() (api/v2/utils.py): pydantic.create_model() in v2 doesn't expose Form/File FieldInfo defaults through __init__.__signature__, so FastAPI treated everything as query params. Replaced with a class factory that builds an explicit inspect.Signature with the correct FieldInfo defaults:

def __init__(self, **kwargs): ...
__init__.__signature__ = inspect.Signature([
    inspect.Parameter("field_name", ..., default=fastapi.Form(...)),
    ...
])

Test infrastructure

  • conftest.py: session-scoped test_app and client fixtures; mocks stevedore loading with an in-process TestModel.
  • test_v2_api.py: 38 tests across 7 classes covering root, v2 version, model list, model metadata, predict (required/optional params, file upload, validation errors), debug, and OpenAPI/Swagger/ReDoc endpoints.

Pre-existing test bug fixed

test_loading_error patched get_available_models (doesn't exist) instead of get_available_model_names, and didn't reset the MODEL singleton — the test only appeared to pass because load_model() short-circuited on the already-loaded singleton.

Copilot AI changed the title Finalize FastAPI refactor and add comprehensive API tests Finalize FastAPI refactor: fix 5 runtime bugs and add API test suite Jul 7, 2026
Copilot AI requested a review from alvarolopez July 7, 2026 08:22
@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

2 participants