Skip to content

Refactored request to skip db prefix #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions arangoasync/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,11 @@ def compress_request(self, request: Request) -> bool:
async def process_request(
self,
request: Request,
skip_db_prefix: bool = False,
) -> Response:
"""Process request, potentially trying multiple hosts.

Args:
request (Request): Request object.
skip_db_prefix (bool): If `True`, do not prepend the database endpoint.

Returns:
Response: Response object.
Expand All @@ -178,7 +176,7 @@ async def process_request(
ConnectionAbortedError: If it can't connect to host(s) within limit.
"""

if not skip_db_prefix:
if request.prefix_needed:
request.endpoint = f"{self._db_endpoint}{request.endpoint}"
host_index = self._host_resolver.get_host_index()
for tries in range(self._host_resolver.max_tries):
Expand Down Expand Up @@ -379,10 +377,11 @@ async def refresh_token(self) -> None:
method=Method.POST,
endpoint="/_open/auth",
data=auth.encode("utf-8"),
prefix_needed=False,
)

try:
resp = await self.process_request(request, skip_db_prefix=True)
resp = await self.process_request(request)
except ClientConnectionAbortedError as e:
raise JWTRefreshError(str(e)) from e
except ServerConnectionError as e:
Expand Down
4 changes: 3 additions & 1 deletion arangoasync/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,9 @@ async def reload_jwt_secrets(self) -> Result[Json]:
References:
- `hot-reload-the-jwt-secrets-from-disk <https://docs.arangodb.com/stable/develop/http-api/authentication/#hot-reload-the-jwt-secrets-from-disk>`__
""" # noqa: 501
request = Request(method=Method.POST, endpoint="/_admin/server/jwt")
request = Request(
method=Method.POST, endpoint="/_admin/server/jwt", prefix_needed=False
)

def response_handler(resp: Response) -> Json:
if not resp.is_success:
Expand Down
5 changes: 5 additions & 0 deletions arangoasync/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Request:
params (dict | None): URL parameters.
data (bytes | None): Request payload.
auth (Auth | None): Authentication.
prefix_needed (bool): Whether the request needs a prefix (e.g., database name).

Attributes:
method (Method): HTTP method.
Expand All @@ -41,6 +42,7 @@ class Request:
params (dict | None): URL parameters.
data (bytes | None): Request payload.
auth (Auth | None): Authentication.
prefix_needed (bool): Whether the request needs a prefix (e.g., database name).
"""

__slots__ = (
Expand All @@ -50,6 +52,7 @@ class Request:
"params",
"data",
"auth",
"prefix_needed",
)

def __init__(
Expand All @@ -60,13 +63,15 @@ def __init__(
params: Optional[Params] = None,
data: Optional[bytes | str] = None,
auth: Optional[Auth] = None,
prefix_needed: bool = True,
) -> None:
self.method: Method = method
self.endpoint: str = endpoint
self.headers: RequestHeaders = headers or dict()
self.params: Params = params or dict()
self.data: Optional[bytes | str] = data
self.auth: Optional[Auth] = auth
self.prefix_needed = prefix_needed

def normalized_headers(self) -> RequestHeaders:
"""Normalize request headers.
Expand Down
Loading