Skip to content

Commit 2fb2f47

Browse files
fix(lock): Fix LockError message when releasing a lock. (#3534)
* fix(lock): raise LockNotOwnedError when release a lock from non-owned thread * change: error raise * fix: linter * fix(lock): async release --------- Co-authored-by: Vladyslav Vildanov <[email protected]>
1 parent 577b4ac commit 2fb2f47

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

redis/asyncio/lock.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ def release(self) -> Awaitable[None]:
249249
"""Releases the already acquired lock"""
250250
expected_token = self.local.token
251251
if expected_token is None:
252-
raise LockError("Cannot release an unlocked lock")
252+
raise LockError(
253+
"Cannot release a lock that's not owned or is already unlocked.",
254+
lock_name=self.name,
255+
)
253256
self.local.token = None
254257
return self.do_release(expected_token)
255258

redis/lock.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ def release(self) -> None:
251251
"""
252252
expected_token = self.local.token
253253
if expected_token is None:
254-
raise LockError("Cannot release an unlocked lock", lock_name=self.name)
254+
raise LockError(
255+
"Cannot release a lock that's not owned or is already unlocked.",
256+
lock_name=self.name,
257+
)
255258
self.local.token = None
256259
self.do_release(expected_token)
257260

0 commit comments

Comments
 (0)