Skip to content

Commit 1e503b2

Browse files
committed
Finish hints for locks
1 parent cb5abd3 commit 1e503b2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/django_mysql/locks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.db import connections
77
from django.db.backends.utils import CursorWrapper
88
from django.db.models import Model
9-
from django.db.transaction import TransactionManagementError, atomic
9+
from django.db.transaction import Atomic, TransactionManagementError, atomic
1010
from django.db.utils import DEFAULT_DB_ALIAS
1111

1212
from django_mysql.exceptions import TimeoutError
@@ -76,7 +76,8 @@ def is_held(self) -> bool:
7676
def holding_connection_id(self) -> int | None:
7777
with self.get_cursor() as cursor:
7878
cursor.execute("SELECT IS_USED_LOCK(%s)", (self.name,))
79-
return cursor.fetchone()[0]
79+
result: int | None = cursor.fetchone()[0]
80+
return result
8081

8182
@classmethod
8283
def held_with_prefix(
@@ -107,6 +108,7 @@ def __init__(
107108
self.read: list[str] = self._process_names(read)
108109
self.write: list[str] = self._process_names(write)
109110
self.db = DEFAULT_DB_ALIAS if using is None else using
111+
self._atomic: Atomic | None = None
110112

111113
def _process_names(self, names: list[str | type[Model]] | None) -> list[str]:
112114
"""
@@ -169,6 +171,7 @@ def release(
169171
) -> None:
170172
connection = connections[self.db]
171173
with connection.cursor() as cursor:
174+
assert self._atomic is not None
172175
self._atomic.__exit__(exc_type, exc_value, exc_traceback)
173176
self._atomic = None
174177
cursor.execute("UNLOCK TABLES")

0 commit comments

Comments
 (0)