Skip to content

Commit 784ee55

Browse files
committed
fix typeerror by patch calls to register_default_jsonb
1 parent 64b69e4 commit 784ee55

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

aws_xray_sdk/ext/psycopg2/patch.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ def patch():
2323
_xray_register_type_fix
2424
)
2525

26-
# wrapt.wrap_function_wrapper(
27-
# 'psycopg2.extras',
28-
# 'register_default_jsonb',
29-
# _xray_register_default_jsonb_fix
30-
# )
26+
wrapt.wrap_function_wrapper(
27+
'psycopg2.extras',
28+
'register_default_jsonb',
29+
_xray_register_default_jsonb_fix
30+
)
3131

3232

3333
def _xray_traced_connect(wrapped, instance, args, kwargs):
@@ -58,12 +58,12 @@ def _xray_register_type_fix(wrapped, instance, args, kwargs):
5858
return wrapped(*our_args, **kwargs)
5959

6060

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)
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)

tests/ext/psycopg2/test_psycopg2.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ def test_register_default_jsonb():
184184
' host=' + dsn['host'] +
185185
' port=' + str(dsn['port']) +
186186
' user=' + dsn['user'])
187-
# test_sql = psycopg2.sql.Identifier('test')
188187

189-
assert psycopg2.extras.register_default_jsonb(None, conn)
190-
assert psycopg2.extras.register_uuid(None, conn.cursor())
188+
assert psycopg2.extras.register_default_jsonb(conn_or_curs=conn, loads=lambda x: x)
189+
assert psycopg2.extras.register_default_jsonb(conn_or_curs=conn.cursor(), loads=lambda x: x)

0 commit comments

Comments
 (0)