@@ -16,7 +16,6 @@ class SQLQueryTriggered(Exception):
16
16
17
17
18
18
class ThreadLocalState (local ):
19
-
20
19
def __init__ (self ):
21
20
self .enabled = True
22
21
@@ -35,7 +34,7 @@ def recording(self, v):
35
34
36
35
37
36
def wrap_cursor (connection , panel ):
38
- if not hasattr (connection , ' _graphene_cursor' ):
37
+ if not hasattr (connection , " _graphene_cursor" ):
39
38
connection ._graphene_cursor = connection .cursor
40
39
41
40
def cursor ():
@@ -46,7 +45,7 @@ def cursor():
46
45
47
46
48
47
def unwrap_cursor (connection ):
49
- if hasattr (connection , ' _graphene_cursor' ):
48
+ if hasattr (connection , " _graphene_cursor" ):
50
49
previous_cursor = connection ._graphene_cursor
51
50
connection .cursor = previous_cursor
52
51
del connection ._graphene_cursor
@@ -87,61 +86,63 @@ def _quote_params(self, params):
87
86
if not params :
88
87
return params
89
88
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 ())
92
90
return list (map (self ._quote_expr , params ))
93
91
94
92
def _decode (self , param ):
95
93
try :
96
94
return force_text (param , strings_only = True )
97
95
except UnicodeDecodeError :
98
- return ' (encoded string)'
96
+ return " (encoded string)"
99
97
100
98
def _record (self , method , sql , params ):
101
99
start_time = time ()
102
100
try :
103
101
return method (sql , params )
104
102
finally :
105
103
stop_time = time ()
106
- duration = ( stop_time - start_time )
107
- _params = ''
104
+ duration = stop_time - start_time
105
+ _params = ""
108
106
try :
109
107
_params = json .dumps (list (map (self ._decode , params )))
110
108
except Exception :
111
109
pass # object not JSON serializable
112
110
113
- alias = getattr (self .db , ' alias' , ' default' )
111
+ alias = getattr (self .db , " alias" , " default" )
114
112
conn = self .db .connection
115
- vendor = getattr (conn , ' vendor' , ' unknown' )
113
+ vendor = getattr (conn , " vendor" , " unknown" )
116
114
117
115
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" ),
129
128
}
130
129
131
- if vendor == ' postgresql' :
130
+ if vendor == " postgresql" :
132
131
# If an erroneous query was ran on the connection, it might
133
132
# be in a state where checking isolation_level raises an
134
133
# exception.
135
134
try :
136
135
iso_level = conn .isolation_level
137
136
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
+ )
145
146
146
147
_sql = DjangoDebugSQL (** params )
147
148
# We keep `sql` to maintain backwards compatibility
0 commit comments