@@ -16,7 +16,6 @@ class SQLQueryTriggered(Exception):
1616
1717
1818class ThreadLocalState (local ):
19-
2019 def __init__ (self ):
2120 self .enabled = True
2221
@@ -35,7 +34,7 @@ def recording(self, v):
3534
3635
3736def wrap_cursor (connection , panel ):
38- if not hasattr (connection , ' _graphene_cursor' ):
37+ if not hasattr (connection , " _graphene_cursor" ):
3938 connection ._graphene_cursor = connection .cursor
4039
4140 def cursor ():
@@ -46,7 +45,7 @@ def cursor():
4645
4746
4847def unwrap_cursor (connection ):
49- if hasattr (connection , ' _graphene_cursor' ):
48+ if hasattr (connection , " _graphene_cursor" ):
5049 previous_cursor = connection ._graphene_cursor
5150 connection .cursor = previous_cursor
5251 del connection ._graphene_cursor
@@ -87,61 +86,63 @@ def _quote_params(self, params):
8786 if not params :
8887 return params
8988 if isinstance (params , dict ):
90- return dict ((key , self ._quote_expr (value ))
91- for key , value in params .items ())
89+ return dict ((key , self ._quote_expr (value )) for key , value in params .items ())
9290 return list (map (self ._quote_expr , params ))
9391
9492 def _decode (self , param ):
9593 try :
9694 return force_text (param , strings_only = True )
9795 except UnicodeDecodeError :
98- return ' (encoded string)'
96+ return " (encoded string)"
9997
10098 def _record (self , method , sql , params ):
10199 start_time = time ()
102100 try :
103101 return method (sql , params )
104102 finally :
105103 stop_time = time ()
106- duration = ( stop_time - start_time )
107- _params = ''
104+ duration = stop_time - start_time
105+ _params = ""
108106 try :
109107 _params = json .dumps (list (map (self ._decode , params )))
110108 except Exception :
111109 pass # object not JSON serializable
112110
113- alias = getattr (self .db , ' alias' , ' default' )
111+ alias = getattr (self .db , " alias" , " default" )
114112 conn = self .db .connection
115- vendor = getattr (conn , ' vendor' , ' unknown' )
113+ vendor = getattr (conn , " vendor" , " unknown" )
116114
117115 params = {
118- 'vendor' : vendor ,
119- 'alias' : alias ,
120- 'sql' : self .db .ops .last_executed_query (
121- self .cursor , sql , self ._quote_params (params )),
122- 'duration' : duration ,
123- 'raw_sql' : sql ,
124- 'params' : _params ,
125- 'start_time' : start_time ,
126- 'stop_time' : stop_time ,
127- 'is_slow' : duration > 10 ,
128- 'is_select' : sql .lower ().strip ().startswith ('select' ),
116+ "vendor" : vendor ,
117+ "alias" : alias ,
118+ "sql" : self .db .ops .last_executed_query (
119+ self .cursor , sql , self ._quote_params (params )
120+ ),
121+ "duration" : duration ,
122+ "raw_sql" : sql ,
123+ "params" : _params ,
124+ "start_time" : start_time ,
125+ "stop_time" : stop_time ,
126+ "is_slow" : duration > 10 ,
127+ "is_select" : sql .lower ().strip ().startswith ("select" ),
129128 }
130129
131- if vendor == ' postgresql' :
130+ if vendor == " postgresql" :
132131 # If an erroneous query was ran on the connection, it might
133132 # be in a state where checking isolation_level raises an
134133 # exception.
135134 try :
136135 iso_level = conn .isolation_level
137136 except conn .InternalError :
138- iso_level = 'unknown'
139- params .update ({
140- 'trans_id' : self .logger .get_transaction_id (alias ),
141- 'trans_status' : conn .get_transaction_status (),
142- 'iso_level' : iso_level ,
143- 'encoding' : conn .encoding ,
144- })
137+ iso_level = "unknown"
138+ params .update (
139+ {
140+ "trans_id" : self .logger .get_transaction_id (alias ),
141+ "trans_status" : conn .get_transaction_status (),
142+ "iso_level" : iso_level ,
143+ "encoding" : conn .encoding ,
144+ }
145+ )
145146
146147 _sql = DjangoDebugSQL (** params )
147148 # We keep `sql` to maintain backwards compatibility
0 commit comments