Skip to content

fix(lock): Fix LockError message when releasing a lock. #3534

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
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
5 changes: 4 additions & 1 deletion redis/asyncio/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ def release(self) -> Awaitable[None]:
"""Releases the already acquired lock"""
expected_token = self.local.token
if expected_token is None:
raise LockError("Cannot release an unlocked lock")
raise LockError(
"Cannot release a lock that's not owned or is already unlocked.",
lock_name=self.name,
)
self.local.token = None
return self.do_release(expected_token)

Expand Down
5 changes: 4 additions & 1 deletion redis/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ def release(self) -> None:
"""
expected_token = self.local.token
if expected_token is None:
raise LockError("Cannot release an unlocked lock", lock_name=self.name)
raise LockError(
"Cannot release a lock that's not owned or is already unlocked.",
lock_name=self.name,
)
self.local.token = None
self.do_release(expected_token)

Expand Down
Loading