@@ -83,7 +83,6 @@ def __setstate__(self, state: dict[str, Any]) -> None:
83
83
84
84
# ------------------------------------
85
85
86
- # internal
87
86
def _ensure_clients (self ) -> None :
88
87
if self .client is None :
89
88
self .client = Redis (
@@ -144,15 +143,14 @@ async def aacquire_lock(
144
143
lock_name = self ._lock_name_for_key (key )
145
144
lock = self ._locks .get (lock_name )
146
145
147
- if lock is not None and isinstance (
148
- lock , AsyncLock
149
- ): # Still need to check if it *is* an AsyncLock to call await .owned()
146
+ if lock is not None and isinstance (lock , AsyncLock ):
150
147
if await lock .owned () and lock .local .token == holder .encode ():
151
148
return True
152
149
else :
153
150
lock = None
154
151
155
152
if lock is None :
153
+ assert self .async_client is not None , "Async client should be initialized"
156
154
new_lock = AsyncLock (
157
155
self .async_client , lock_name , timeout = hold_timeout , thread_local = False
158
156
)
@@ -219,6 +217,7 @@ def wait_for_lock(self, key: str, timeout: Optional[float] = None) -> bool:
219
217
async def await_for_lock (self , key : str , timeout : Optional [float ] = None ) -> bool :
220
218
self ._ensure_clients ()
221
219
lock_name = self ._lock_name_for_key (key )
220
+ assert self .async_client is not None , "Async client should be initialized"
222
221
lock = AsyncLock (
223
222
self .async_client , lock_name
224
223
) # Create a temporary lock for waiting
0 commit comments