From eef91a7db0ddec3260dd87bb5a2397a4d4dbb062 Mon Sep 17 00:00:00 2001 From: Vadim Laletin Date: Sun, 29 Mar 2026 08:51:09 +0200 Subject: [PATCH] Revert #97 --- CHANGELOG.md | 7 ++++++- aidbox_python_sdk/__init__.py | 2 +- aidbox_python_sdk/handlers.py | 9 +-------- main.py | 34 +--------------------------------- tests/test_sdk.py | 12 ------------ 5 files changed, 9 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd54b58..5a25db4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ -## 0.2.1 +## 0.2.2 + +- Revert BaseFHIRError exceptions from fhir-py in operation handlers b + + +## 0.2.1 (yanked) - Handle BaseFHIRError exceptions from fhir-py in operation handlers diff --git a/aidbox_python_sdk/__init__.py b/aidbox_python_sdk/__init__.py index f0e91f8..4fcbaa4 100644 --- a/aidbox_python_sdk/__init__.py +++ b/aidbox_python_sdk/__init__.py @@ -1,5 +1,5 @@ __title__ = "aidbox-python-sdk" -__version__ = "0.2.1" +__version__ = "0.2.2" __author__ = "beda.software" __license__ = "None" __copyright__ = "Copyright 2024 beda.software" diff --git a/aidbox_python_sdk/handlers.py b/aidbox_python_sdk/handlers.py index 9e23cfe..e2b8f0a 100644 --- a/aidbox_python_sdk/handlers.py +++ b/aidbox_python_sdk/handlers.py @@ -1,10 +1,9 @@ import asyncio -import json import logging from typing import Any from aiohttp import web -from fhirpy.base.exceptions import BaseFHIRError, OperationOutcome +from fhirpy.base.exceptions import OperationOutcome from . import app_keys as ak @@ -49,12 +48,6 @@ async def operation(request: web.Request, data: dict[str, Any]): return result except OperationOutcome as exc: return web.json_response(exc.resource, status=422) - except BaseFHIRError as exc: - try: - payload = json.loads(str(exc)) - return web.json_response(payload, status=422) - except (json.JSONDecodeError, TypeError): - return web.Response(text=str(exc), status=422, content_type="text/plain") TYPES = { diff --git a/main.py b/main.py index d3202fb..d2e270f 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,10 @@ import asyncio -import json import logging from datetime import datetime import coloredlogs from aiohttp import web -from fhirpy.base.exceptions import BaseFHIRError, OperationOutcome +from fhirpy.base.exceptions import OperationOutcome from sqlalchemy.sql.expression import select from aidbox_python_sdk.db import DBProxy @@ -161,34 +160,3 @@ async def observation_custom_op(operation, request): ) async def operation_outcome_test_op(operation, request): raise OperationOutcome(reason="test reason") - - -@sdk.operation( - ["POST"], - ["$base-fhir-error-json-test"], -) -async def base_fhir_error_json_test_op(operation, request): - raise BaseFHIRError( - json.dumps( - { - "resourceType": "OperationOutcome", - "id": "not-found", - "text": {"status": "generated", "div": "Resource Patient/id not found"}, - "issue": [ - { - "severity": "fatal", - "code": "not-found", - "diagnostics": "Resource Patient/id not found", - } - ], - } - ) - ) - - -@sdk.operation( - ["POST"], - ["$base-fhir-error-text-test"], -) -async def base_fhir_error_text_test_op(operation, request): - raise BaseFHIRError("plain") diff --git a/tests/test_sdk.py b/tests/test_sdk.py index fc01a35..5b70b46 100644 --- a/tests/test_sdk.py +++ b/tests/test_sdk.py @@ -192,18 +192,6 @@ async def test_aidbox_db_fixture(client, aidbox_db: DBProxy, safe_db): assert app_ids == [{"id": "app-test"}] -async def test_operation_base_fhir_error_json_test_op(aidbox_client): - with pytest.raises(OperationOutcome) as exc: - await aidbox_client.execute("/$base-fhir-error-json-test") - assert exc.value.resource.get("issue")[0].get("diagnostics") == "Resource Patient/id not found" - - -async def test_operation_base_fhir_error_text_test_op(aidbox_client): - with pytest.raises(OperationOutcome) as exc: - await aidbox_client.execute("/$base-fhir-error-text-test") - assert exc.value.resource.get("issue")[0].get("diagnostics") == "plain" - - async def test_operation_outcome_test_op(aidbox_client): with pytest.raises(OperationOutcome) as exc: await aidbox_client.execute("/$operation-outcome-test")