7
7
8
8
9
9
def patch ():
10
-
11
10
wrapt .wrap_function_wrapper (
12
11
'psycopg2' ,
13
12
'connect' ,
@@ -24,11 +23,16 @@ def patch():
24
23
_xray_register_type_fix
25
24
)
26
25
26
+ wrapt .wrap_function_wrapper (
27
+ 'psycopg2.extras' ,
28
+ 'register_default_jsonb' ,
29
+ _xray_register_default_jsonb_fix
30
+ )
27
31
28
- def _xray_traced_connect (wrapped , instance , args , kwargs ):
29
32
33
+ def _xray_traced_connect (wrapped , instance , args , kwargs ):
30
34
conn = wrapped (* args , ** kwargs )
31
- parameterized_dsn = { c [0 ]: c [- 1 ] for c in map (methodcaller ('split' , '=' ), conn .dsn .split (' ' ))}
35
+ parameterized_dsn = {c [0 ]: c [- 1 ] for c in map (methodcaller ('split' , '=' ), conn .dsn .split (' ' ))}
32
36
meta = {
33
37
'database_type' : 'PostgreSQL' ,
34
38
'url' : 'postgresql://{}@{}:{}/{}' .format (
@@ -44,10 +48,22 @@ def _xray_traced_connect(wrapped, instance, args, kwargs):
44
48
45
49
return XRayTracedConn (conn , meta )
46
50
51
+
47
52
def _xray_register_type_fix (wrapped , instance , args , kwargs ):
48
53
"""Send the actual connection or curser to register type."""
49
54
our_args = list (copy .copy (args ))
50
55
if len (our_args ) == 2 and isinstance (our_args [1 ], (XRayTracedConn , XRayTracedCursor )):
51
56
our_args [1 ] = our_args [1 ].__wrapped__
52
57
53
58
return wrapped (* our_args , ** kwargs )
59
+
60
+
61
+ def _xray_register_default_jsonb_fix (wrapped , instance , args , kwargs ):
62
+ our_kwargs = dict ()
63
+ for key , value in kwargs .items ():
64
+ if key == "conn_or_curs" and isinstance (value , (XRayTracedConn , XRayTracedCursor )):
65
+ # unwrap the connection or cursor to be sent to register_default_jsonb
66
+ value = value .__wrapped__
67
+ our_kwargs [key ] = value
68
+
69
+ return wrapped (* args , ** our_kwargs )
0 commit comments