@@ -169,7 +169,8 @@ def get(cls, using: str = DEFAULT_DB_ALIAS) -> int:
169
169
# database connections in Django, and the reason was not clear
170
170
with connections [using ].cursor () as cursor :
171
171
cursor .execute ("SELECT LAST_INSERT_ID()" )
172
- return cursor .fetchone ()[0 ]
172
+ id_ : int = cursor .fetchone ()[0 ]
173
+ return id_
173
174
174
175
175
176
# JSON Functions
@@ -258,7 +259,11 @@ def as_sql(
258
259
if connection .vendor != "mysql" : # pragma: no cover
259
260
raise AssertionError ("JSONValue only supports MySQL/MariaDB" )
260
261
json_string = json .dumps (self ._data , allow_nan = False )
261
- if connection .vendor == "mysql" and connection .mysql_is_mariadb :
262
+ if (
263
+ connection .vendor == "mysql"
264
+ # type narrowed by vendor check
265
+ and connection .mysql_is_mariadb # type: ignore [attr-defined]
266
+ ):
262
267
# MariaDB doesn't support explicit cast to JSON.
263
268
return "JSON_EXTRACT(%s, '$')" , (json_string ,)
264
269
else :
@@ -270,7 +275,7 @@ def __init__(
270
275
self ,
271
276
expression : ExpressionArgument ,
272
277
data : dict [
273
- str ,
278
+ ExpressionArgument ,
274
279
(
275
280
ExpressionArgument
276
281
| None
@@ -288,12 +293,12 @@ def __init__(
288
293
exprs = [expression ]
289
294
290
295
for path , value in data .items ():
291
- if not hasattr (path , "resolve_expression" ):
296
+ if not isinstance (path , Expression ):
292
297
path = Value (path )
293
298
294
299
exprs .append (path )
295
300
296
- if not hasattr (value , "resolve_expression" ):
301
+ if not isinstance (value , Expression ):
297
302
value = JSONValue (value )
298
303
299
304
exprs .append (value )
@@ -392,20 +397,20 @@ def __init__(
392
397
self ,
393
398
expression : ExpressionArgument ,
394
399
to_add : dict [
395
- str ,
400
+ ExpressionArgument ,
396
401
ExpressionArgument | float | int | dt .date | dt .time | dt .datetime ,
397
402
],
398
403
) -> None :
399
404
from django_mysql .models .fields import DynamicField
400
405
401
406
expressions = [expression ]
402
407
for name , value in to_add .items ():
403
- if not hasattr (name , "resolve_expression" ):
408
+ if not isinstance (name , Expression ):
404
409
name = Value (name )
405
410
406
- if isinstance (value , dict ): # type: ignore [unreachable]
411
+ if isinstance (value , dict ):
407
412
raise ValueError ("ColumnAdd with nested values is not supported" )
408
- if not hasattr (value , "resolve_expression" ):
413
+ if not isinstance (value , Expression ):
409
414
value = Value (value )
410
415
411
416
expressions .extend ((name , value ))
0 commit comments