Skip to content

Commit 64b69e4

Browse files
committed
testing the call to register_default_jsonb
1 parent 90b3b9e commit 64b69e4

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

aws_xray_sdk/ext/psycopg2/patch.py

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

26-
# We should in general not patch internal methods (pyscopg2._json.register_type in this case).
27-
# But there isn't a better workaround than this for the time being.
28-
# Please see the GH issue for details: https://github.com/aws/aws-xray-sdk-python/issues/243
29-
wrapt.wrap_function_wrapper(
30-
'psycopg2._json',
31-
'register_type',
32-
_xray_register_type_fix
33-
)
26+
# wrapt.wrap_function_wrapper(
27+
# 'psycopg2.extras',
28+
# 'register_default_jsonb',
29+
# _xray_register_default_jsonb_fix
30+
# )
3431

3532

3633
def _xray_traced_connect(wrapped, instance, args, kwargs):
@@ -59,3 +56,14 @@ def _xray_register_type_fix(wrapped, instance, args, kwargs):
5956
our_args[1] = our_args[1].__wrapped__
6057

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

tests/ext/psycopg2/test_psycopg2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,18 @@ def test_query_as_string():
173173
test_sql = psycopg2.sql.Identifier('test')
174174
assert test_sql.as_string(conn)
175175
assert test_sql.as_string(conn.cursor())
176+
177+
178+
def test_register_default_jsonb():
179+
with testing.postgresql.Postgresql() as postgresql:
180+
url = postgresql.url()
181+
dsn = postgresql.dsn()
182+
conn = psycopg2.connect('dbname=' + dsn['database'] +
183+
' password=mypassword' +
184+
' host=' + dsn['host'] +
185+
' port=' + str(dsn['port']) +
186+
' user=' + dsn['user'])
187+
# test_sql = psycopg2.sql.Identifier('test')
188+
189+
assert psycopg2.extras.register_default_jsonb(None, conn)
190+
assert psycopg2.extras.register_uuid(None, conn.cursor())

0 commit comments

Comments
 (0)