@@ -233,7 +233,8 @@ def get(cls, using: str = DEFAULT_DB_ALIAS) -> int:
233
233
# database connections in Django, and the reason was not clear
234
234
with connections [using ].cursor () as cursor :
235
235
cursor .execute ("SELECT LAST_INSERT_ID()" )
236
- return cursor .fetchone ()[0 ]
236
+ id_ : int = cursor .fetchone ()[0 ]
237
+ return id_
237
238
238
239
239
240
# JSON Functions
@@ -322,7 +323,11 @@ def as_sql(
322
323
if connection .vendor != "mysql" : # pragma: no cover
323
324
raise AssertionError ("JSONValue only supports MySQL/MariaDB" )
324
325
json_string = json .dumps (self ._data , allow_nan = False )
325
- if connection .vendor == "mysql" and connection .mysql_is_mariadb :
326
+ if (
327
+ connection .vendor == "mysql"
328
+ # type narrowed by vendor check
329
+ and connection .mysql_is_mariadb # type: ignore [attr-defined]
330
+ ):
326
331
# MariaDB doesn't support explicit cast to JSON.
327
332
return "JSON_EXTRACT(%s, '$')" , (json_string ,)
328
333
else :
@@ -334,7 +339,7 @@ def __init__(
334
339
self ,
335
340
expression : ExpressionArgument ,
336
341
data : dict [
337
- str ,
342
+ ExpressionArgument ,
338
343
(
339
344
ExpressionArgument
340
345
| None
@@ -352,12 +357,12 @@ def __init__(
352
357
exprs = [expression ]
353
358
354
359
for path , value in data .items ():
355
- if not hasattr (path , "resolve_expression" ):
360
+ if not isinstance (path , Expression ):
356
361
path = Value (path )
357
362
358
363
exprs .append (path )
359
364
360
- if not hasattr (value , "resolve_expression" ):
365
+ if not isinstance (value , Expression ):
361
366
value = JSONValue (value )
362
367
363
368
exprs .append (value )
@@ -456,19 +461,20 @@ def __init__(
456
461
self ,
457
462
expression : ExpressionArgument ,
458
463
to_add : dict [
459
- str , ExpressionArgument | float | int | dt .date | dt .time | dt .datetime
464
+ ExpressionArgument ,
465
+ ExpressionArgument | float | int | dt .date | dt .time | dt .datetime ,
460
466
],
461
467
) -> None :
462
468
from django_mysql .models .fields import DynamicField
463
469
464
470
expressions = [expression ]
465
471
for name , value in to_add .items ():
466
- if not hasattr (name , "resolve_expression" ):
472
+ if not isinstance (name , Expression ):
467
473
name = Value (name )
468
474
469
- if isinstance (value , dict ): # type: ignore [unreachable]
475
+ if isinstance (value , dict ):
470
476
raise ValueError ("ColumnAdd with nested values is not supported" )
471
- if not hasattr (value , "resolve_expression" ):
477
+ if not isinstance (value , Expression ):
472
478
value = Value (value )
473
479
474
480
expressions .extend ((name , value ))
0 commit comments