Skip to content

Commit 28b54b4

Browse files
author
Johannes Lichtenberger
committed
fix: raise SirixServerError for 500 errors in resource_exists
Previously, resource_exists() would return False for any non-200 status, including 500 server errors. This masked server-side bugs like data corruption, causing tests to pass for the wrong reason. Now: - 200: return True (resource exists) - 404: return False (resource doesn't exist) - 5xx: raise SirixServerError (server error)
1 parent 7b8670b commit 28b54b4

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

pysirix/async_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ async def resource_exists(self, db_name: str, db_type: DBType, name: str) -> boo
5858
)
5959
if resp.status_code == 200:
6060
return True
61-
return False
61+
if resp.status_code == 404:
62+
return False
63+
# For other errors (especially 5xx), raise an exception
64+
with include_response_text_in_errors():
65+
resp.raise_for_status()
66+
return False # Unreachable, but satisfies type checker
6267

6368
async def create_resource(
6469
self,

pysirix/sync_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,17 @@ def resource_exists(self, db_name: str, db_type: DBType, name: str) -> bool:
9494
:param db_type: the type of the database.
9595
:param name: the name of the resource.
9696
:return: a ``bool`` indicating the existence (or lack thereof) of the resource.
97-
:raises: :py:class:`pysirix.SirixServerError`.
97+
:raises: :py:class:`pysirix.SirixServerError` for server errors (5xx).
9898
"""
9999
resp = self.client.head(f"{db_name}/{name}", headers={"Accept": db_type.value})
100100
if resp.status_code == 200:
101101
return True
102-
return False
102+
if resp.status_code == 404:
103+
return False
104+
# For other errors (especially 5xx), raise an exception
105+
with include_response_text_in_errors():
106+
resp.raise_for_status()
107+
return False # Unreachable, but satisfies type checker
103108

104109
def create_resource(
105110
self,

0 commit comments

Comments
 (0)