11# -*- coding: utf-8 -*-
22from __future__ import absolute_import
33
4- import contextlib
54import sys
65import weakref
6+ import contextlib
77
88from django import VERSION as DJANGO_VERSION # type: ignore
99from django .db .models .query import QuerySet # type: ignore
@@ -332,11 +332,12 @@ def format_sql(sql, params):
332332 return sql , rv
333333
334334
335+ @contextlib .contextmanager
335336def record_sql (sql , param_list , cursor = None ):
336337 # type: (Any, Any, Any) -> Generator
337338 hub = Hub .current
338339 if hub .get_integration (DjangoIntegration ) is None :
339- yield
340+ yield None
340341 return
341342
342343 formatted_queries = []
@@ -374,7 +375,8 @@ def record_sql(sql, param_list, cursor=None):
374375 if real_sql :
375376 formatted_queries .append (real_sql )
376377
377- return record_sql_queries (hub , formatted_queries )
378+ with record_sql_query (hub , formatted_queries ):
379+ yield
378380
379381
380382def install_sql_hook ():
@@ -397,7 +399,7 @@ def execute(self, sql, params=None):
397399 return real_execute (self , sql , params )
398400
399401 def executemany (self , sql , param_list ):
400- with record_many_sql (sql , param_list , self .cursor ):
402+ with record_sql (sql , param_list , self .cursor ):
401403 return real_executemany (self , sql , param_list )
402404
403405 CursorWrapper .execute = execute
0 commit comments