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