Skip to content

Commit 66617e5

Browse files
ImTotemclaude
andcommitted
fix(authz): use SyncClient instead of async Client
authzed.api.v1.Client is async (returns UnaryUnaryCall futures). SyncClient returns responses directly. Problem solved. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d101d37 commit 66617e5

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/bcsd_api/authz/client.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from authzed.api.v1 import (
22
CheckPermissionRequest,
33
CheckPermissionResponse,
4-
Client,
4+
SyncClient as Client,
55
ObjectReference,
66
Relationship,
77
RelationshipUpdate,
@@ -39,12 +39,6 @@ def _update(operation, res_type: str, res_id: str, relation: str, user_id: str)
3939
)
4040

4141

42-
def _resolve(call):
43-
if callable(getattr(call, "result", None)):
44-
return call.result() # type: ignore[union-attr]
45-
return call
46-
47-
4842
class AuthzClient:
4943
def __init__(self, endpoint: str, token: str):
5044
self._client = Client(
@@ -53,14 +47,13 @@ def __init__(self, endpoint: str, token: str):
5347
)
5448

5549
def check(self, res_type: str, res_id: str, permission: str, user_id: str) -> bool:
56-
call = self._client.CheckPermission(
50+
resp = self._client.CheckPermission(
5751
CheckPermissionRequest(
5852
resource=_object_ref(res_type, res_id),
5953
permission=permission,
6054
subject=_subject_ref(user_id),
6155
)
6256
)
63-
resp = _resolve(call)
6457
return resp.permissionship == _HAS
6558

6659
def add_relation(self, res_type: str, res_id: str, relation: str, user_id: str) -> None:
@@ -70,9 +63,9 @@ def remove_relation(self, res_type: str, res_id: str, relation: str, user_id: st
7063
self._write(_DELETE, res_type, res_id, relation, user_id)
7164

7265
def write_schema(self, schema: str) -> None:
73-
_resolve(self._client.WriteSchema(WriteSchemaRequest(schema=schema)))
66+
self._client.WriteSchema(WriteSchemaRequest(schema=schema))
7467

7568
def _write(self, operation: int, res_type: str, res_id: str, relation: str, user_id: str) -> None:
76-
_resolve(self._client.WriteRelationships(
69+
self._client.WriteRelationships(
7770
WriteRelationshipsRequest(updates=[_update(operation, res_type, res_id, relation, user_id)])
78-
))
71+
)

0 commit comments

Comments
 (0)