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