38
38
39
39
import attr
40
40
from prometheus_client import Histogram
41
- from typing_extensions import Literal
41
+ from typing_extensions import Concatenate , Literal , ParamSpec
42
42
43
43
from twisted .enterprise import adbapi
44
44
@@ -194,7 +194,7 @@ def __getattr__(self, name):
194
194
# The type of entry which goes on our after_callbacks and exception_callbacks lists.
195
195
_CallbackListEntry = Tuple [Callable [..., object ], Iterable [Any ], Dict [str , Any ]]
196
196
197
-
197
+ P = ParamSpec ( "P" )
198
198
R = TypeVar ("R" )
199
199
200
200
@@ -339,7 +339,13 @@ def _make_sql_one_line(self, sql: str) -> str:
339
339
"Strip newlines out of SQL so that the loggers in the DB are on one line"
340
340
return " " .join (line .strip () for line in sql .splitlines () if line .strip ())
341
341
342
- def _do_execute (self , func : Callable [..., R ], sql : str , * args : Any ) -> R :
342
+ def _do_execute (
343
+ self ,
344
+ func : Callable [Concatenate [str , P ], R ],
345
+ sql : str ,
346
+ * args : P .args ,
347
+ ** kwargs : P .kwargs ,
348
+ ) -> R :
343
349
sql = self ._make_sql_one_line (sql )
344
350
345
351
# TODO(paul): Maybe use 'info' and 'debug' for values?
@@ -348,7 +354,10 @@ def _do_execute(self, func: Callable[..., R], sql: str, *args: Any) -> R:
348
354
sql = self .database_engine .convert_param_style (sql )
349
355
if args :
350
356
try :
351
- sql_logger .debug ("[SQL values] {%s} %r" , self .name , args [0 ])
357
+ # The type-ignore should be redundant once mypy releases a version with
358
+ # https://github.com/python/mypy/pull/12668. (`args` might be empty,
359
+ # (but we'll catch the index error if so.)
360
+ sql_logger .debug ("[SQL values] {%s} %r" , self .name , args [0 ]) # type: ignore[index]
352
361
except Exception :
353
362
# Don't let logging failures stop SQL from working
354
363
pass
@@ -363,7 +372,7 @@ def _do_execute(self, func: Callable[..., R], sql: str, *args: Any) -> R:
363
372
opentracing .tags .DATABASE_STATEMENT : sql ,
364
373
},
365
374
):
366
- return func (sql , * args )
375
+ return func (sql , * args , ** kwargs )
367
376
except Exception as e :
368
377
sql_logger .debug ("[SQL FAIL] {%s} %s" , self .name , e )
369
378
raise
0 commit comments