diff --git a/httpstan/views.py b/httpstan/views.py index 7b4f7e3f8..4e97c6b77 100644 --- a/httpstan/views.py +++ b/httpstan/views.py @@ -389,6 +389,9 @@ def _services_call_done(operation: dict, future: asyncio.Future) -> None: ) logger.critical(message) operation["result"] = _make_error(message, status=status) + # Delete messages associated with the fit. If initialization + # fails, for example, messages will exist on disk. Remove them. + httpstan.cache.delete_fit(operation["metadata"]["fit"]["name"]) else: logger.info(f"Operation `{operation['name']}` finished.") operation["result"] = schemas.Fit().load(operation["metadata"]["fit"]) diff --git a/tests/test_sampling_exceptions.py b/tests/test_sampling_exceptions.py index 3bd226781..f58c8993b 100644 --- a/tests/test_sampling_exceptions.py +++ b/tests/test_sampling_exceptions.py @@ -32,27 +32,12 @@ async def test_sampling_initialization_failed(api_url: str) -> None: assert operation["result"].get("code") == 400 assert "Initialization failed." in operation["result"]["message"] - # recover the error messages sent to `logger` - # note that the fit name is retrieved from metadata. If sampling had - # completed without error, it would be available under `result`. + # verify the partial fit has been deleted. fit_name = operation["metadata"]["fit"]["name"] - - # verify operation finished and that fit is available async with aiohttp.ClientSession() as session: fit_url = f"{api_url}/{fit_name}" async with session.get(fit_url) as resp: - assert resp.status == 200 - - # verify (error) messages are available - fit_bytes_ = await helpers.fit_bytes(api_url, fit_name) - assert isinstance(fit_bytes_, bytes) - messages = helpers.decode_messages(fit_bytes_) - - assert len(messages) > 100 - - # first message should be an "Rejecting initial value" message. - error_message = messages[0]["values"].pop() - assert "Rejecting initial value" in error_message + assert resp.status == 404 @pytest.mark.asyncio