aidbox-python-sdk 0.2.1__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {aidbox_python_sdk-0.2.1/aidbox_python_sdk.egg-info → aidbox_python_sdk-0.2.3}/PKG-INFO +1 -1
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/__init__.py +2 -2
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/db.py +41 -4
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/handlers.py +1 -8
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/pytest_plugin.py +2 -1
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3/aidbox_python_sdk.egg-info}/PKG-INFO +1 -1
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/tests/test_sdk.py +0 -12
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/LICENSE.md +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/MANIFEST.in +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/README.md +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/aidboxpy.py +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/app_keys.py +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/db_migrations.py +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/exceptions.py +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/main.py +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/py.typed +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/sdk.py +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/settings.py +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk/types.py +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk.egg-info/SOURCES.txt +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk.egg-info/dependency_links.txt +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk.egg-info/not-zip-safe +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk.egg-info/requires.txt +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk.egg-info/top_level.txt +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/pyproject.toml +0 -0
- {aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/setup.cfg +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
__title__ = "aidbox-python-sdk"
|
|
2
|
-
__version__ = "0.2.
|
|
2
|
+
__version__ = "0.2.3"
|
|
3
3
|
__author__ = "beda.software"
|
|
4
4
|
__license__ = "None"
|
|
5
|
-
__copyright__ = "Copyright
|
|
5
|
+
__copyright__ = "Copyright 2026 beda.software"
|
|
6
6
|
|
|
7
7
|
# Version synonym
|
|
8
8
|
VERSION = __version__
|
|
@@ -22,6 +22,36 @@ from aidbox_python_sdk.settings import Settings
|
|
|
22
22
|
|
|
23
23
|
from .exceptions import AidboxDBException
|
|
24
24
|
|
|
25
|
+
|
|
26
|
+
def parse_psql_response(response):
|
|
27
|
+
"""
|
|
28
|
+
Normalizes a $psql response into a list of result sets (one per statement).
|
|
29
|
+
Supports both formats:
|
|
30
|
+
- pre-2604: [{status, result: [row, ...], ...}]
|
|
31
|
+
- 2604+: {status, result: [{type, data: [row, ...]}, ...], ...}
|
|
32
|
+
Raises AidboxDBException on error status.
|
|
33
|
+
"""
|
|
34
|
+
entry = response[0] if isinstance(response, list) else response
|
|
35
|
+
|
|
36
|
+
if entry.get("status") == "error":
|
|
37
|
+
raise AidboxDBException(entry)
|
|
38
|
+
|
|
39
|
+
result = entry.get("result")
|
|
40
|
+
|
|
41
|
+
if not isinstance(result, list):
|
|
42
|
+
return [result] # None or True (old format execute=true)
|
|
43
|
+
|
|
44
|
+
if not result:
|
|
45
|
+
return [result]
|
|
46
|
+
|
|
47
|
+
# New format (2604+): result items carry {type, data}
|
|
48
|
+
if isinstance(result[0], dict) and "data" in result[0]:
|
|
49
|
+
return [rset["data"] for rset in result]
|
|
50
|
+
|
|
51
|
+
# Old format: single flat list of rows
|
|
52
|
+
return [result]
|
|
53
|
+
|
|
54
|
+
|
|
25
55
|
logger = logging.getLogger("aidbox_sdk.db")
|
|
26
56
|
table_metadata = MetaData()
|
|
27
57
|
|
|
@@ -124,10 +154,17 @@ class DBProxy:
|
|
|
124
154
|
) as resp:
|
|
125
155
|
logger.debug("$psql answer %s", await resp.text())
|
|
126
156
|
results = await resp.json()
|
|
127
|
-
|
|
128
|
-
if
|
|
129
|
-
|
|
130
|
-
|
|
157
|
+
result = parse_psql_response(results)
|
|
158
|
+
if execute:
|
|
159
|
+
return True
|
|
160
|
+
if len(result) > 1:
|
|
161
|
+
raise AidboxDBException(
|
|
162
|
+
{
|
|
163
|
+
"status": "error",
|
|
164
|
+
"error": "Multiple result sets returned; use execute=True for multi-statement queries",
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
return result[0]
|
|
131
168
|
|
|
132
169
|
def compile_statement(self, statement):
|
|
133
170
|
return str(
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
import json
|
|
3
2
|
import logging
|
|
4
3
|
from typing import Any
|
|
5
4
|
|
|
6
5
|
from aiohttp import web
|
|
7
|
-
from fhirpy.base.exceptions import
|
|
6
|
+
from fhirpy.base.exceptions import OperationOutcome
|
|
8
7
|
|
|
9
8
|
from . import app_keys as ak
|
|
10
9
|
|
|
@@ -49,12 +48,6 @@ async def operation(request: web.Request, data: dict[str, Any]):
|
|
|
49
48
|
return result
|
|
50
49
|
except OperationOutcome as exc:
|
|
51
50
|
return web.json_response(exc.resource, status=422)
|
|
52
|
-
except BaseFHIRError as exc:
|
|
53
|
-
try:
|
|
54
|
-
payload = json.loads(str(exc))
|
|
55
|
-
return web.json_response(payload, status=422)
|
|
56
|
-
except (json.JSONDecodeError, TypeError):
|
|
57
|
-
return web.Response(text=str(exc), status=422, content_type="text/plain")
|
|
58
51
|
|
|
59
52
|
|
|
60
53
|
TYPES = {
|
|
@@ -13,6 +13,7 @@ from yarl import URL
|
|
|
13
13
|
from aidbox_python_sdk.aidboxpy import AsyncAidboxClient
|
|
14
14
|
|
|
15
15
|
from . import app_keys as ak
|
|
16
|
+
from .db import parse_psql_response
|
|
16
17
|
|
|
17
18
|
_TEST_SERVER_URL = "http://127.0.0.1:8081"
|
|
18
19
|
|
|
@@ -100,7 +101,7 @@ async def safe_db(aidbox_client: AsyncAidboxClient, sdk):
|
|
|
100
101
|
"/$psql",
|
|
101
102
|
data={"query": "SELECT last_value from transaction_id_seq;"},
|
|
102
103
|
)
|
|
103
|
-
txid = results[0][
|
|
104
|
+
txid = parse_psql_response(results)[0][0]["last_value"]
|
|
104
105
|
sdk._test_start_txid = int(txid)
|
|
105
106
|
|
|
106
107
|
yield txid
|
|
@@ -192,18 +192,6 @@ async def test_aidbox_db_fixture(client, aidbox_db: DBProxy, safe_db):
|
|
|
192
192
|
assert app_ids == [{"id": "app-test"}]
|
|
193
193
|
|
|
194
194
|
|
|
195
|
-
async def test_operation_base_fhir_error_json_test_op(aidbox_client):
|
|
196
|
-
with pytest.raises(OperationOutcome) as exc:
|
|
197
|
-
await aidbox_client.execute("/$base-fhir-error-json-test")
|
|
198
|
-
assert exc.value.resource.get("issue")[0].get("diagnostics") == "Resource Patient/id not found"
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
async def test_operation_base_fhir_error_text_test_op(aidbox_client):
|
|
202
|
-
with pytest.raises(OperationOutcome) as exc:
|
|
203
|
-
await aidbox_client.execute("/$base-fhir-error-text-test")
|
|
204
|
-
assert exc.value.resource.get("issue")[0].get("diagnostics") == "plain"
|
|
205
|
-
|
|
206
|
-
|
|
207
195
|
async def test_operation_outcome_test_op(aidbox_client):
|
|
208
196
|
with pytest.raises(OperationOutcome) as exc:
|
|
209
197
|
await aidbox_client.execute("/$operation-outcome-test")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidbox_python_sdk-0.2.1 → aidbox_python_sdk-0.2.3}/aidbox_python_sdk.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|