Skip to content

Commit 276ecf3

Browse files
committed
Finish hints for locks
1 parent c6baf6c commit 276ecf3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/django_mysql/locks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +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 Atomic
910
from django.db.transaction import atomic
1011
from django.db.transaction import TransactionManagementError
1112
from django.db.utils import DEFAULT_DB_ALIAS
@@ -77,7 +78,8 @@ def is_held(self) -> bool:
7778
def holding_connection_id(self) -> int | None:
7879
with self.get_cursor() as cursor:
7980
cursor.execute("SELECT IS_USED_LOCK(%s)", (self.name,))
80-
return cursor.fetchone()[0]
81+
result: int | None = cursor.fetchone()[0]
82+
return result
8183

8284
@classmethod
8385
def held_with_prefix(
@@ -108,6 +110,7 @@ def __init__(
108110
self.read: list[str] = self._process_names(read)
109111
self.write: list[str] = self._process_names(write)
110112
self.db = DEFAULT_DB_ALIAS if using is None else using
113+
self._atomic: Atomic | None = None
111114

112115
def _process_names(self, names: list[str | type[Model]] | None) -> list[str]:
113116
"""
@@ -170,6 +173,7 @@ def release(
170173
) -> None:
171174
connection = connections[self.db]
172175
with connection.cursor() as cursor:
176+
assert self._atomic is not None
173177
self._atomic.__exit__(exc_type, exc_value, exc_traceback)
174178
self._atomic = None
175179
cursor.execute("UNLOCK TABLES")

0 commit comments

Comments
 (0)