Skip to content

Commit

Permalink
Add fix for SyncPDPApi and handle iscoroutine_func
Browse files Browse the repository at this point in the history
  • Loading branch information
maya-barak committed Apr 18, 2024
1 parent 58bdfe1 commit ea8ebcf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 11 additions & 2 deletions permit/pdp_api/pdp_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from .role_assignments import RoleAssignmentsApi


class SyncRoleAssignmentsApi(RoleAssignmentsApi, metaclass=SyncClass):
pass


class PermitPdpApiClient:
def __init__(self, config: PermitConfig):
"""
Expand All @@ -26,5 +30,10 @@ def role_assignments(self) -> RoleAssignmentsApi:
return self._role_assignments


class SyncPDPApi(PermitPdpApiClient, metaclass=SyncClass):
pass
class SyncPDPApi(PermitPdpApiClient):
def __init__(self, config: PermitConfig):
self._role_assignments = SyncRoleAssignmentsApi(config)

@property
def role_assignments(self) -> SyncRoleAssignmentsApi:
return self._role_assignments
8 changes: 6 additions & 2 deletions permit/utils/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ def __new__(mcs, name, bases, class_dict):
continue

attr = getattr(class_obj, name)

if callable(attr) and iscoroutine_func(attr):
if attr.__class__.__name__ == "cython_function_or_method":
# Handle cython method
is_coroutine = True
else:
is_coroutine = iscoroutine_func(attr)
if callable(attr) and is_coroutine:
# monkey-patch public method using async_to_sync decorator
setattr(class_obj, name, async_to_sync(attr))

Expand Down

0 comments on commit ea8ebcf

Please sign in to comment.