Skip to content

Commit 3e78683

Browse files
author
Stefan Tjarks
committed
contrib.psycopg: Patch all imports of register_type
`register_type` was patched in #96, though only in psycopg.extensions. The function is defined in psycopg2._psycopg and imported in psycopg2._json neither of them are patched and if used cause a TypeError.
1 parent 4794988 commit 3e78683

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

ddtrace/contrib/psycopg/patch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,10 @@ def _unroll_args(obj, scope=None):
9999
(psycopg2.extensions.register_type,
100100
psycopg2.extensions, 'register_type',
101101
_extensions_register_type),
102+
(psycopg2._psycopg.register_type,
103+
psycopg2._psycopg, 'register_type',
104+
_extensions_register_type),
105+
(psycopg2._json.register_type,
106+
psycopg2._json, 'register_type',
107+
_extensions_register_type),
102108
]

tests/contrib/psycopg/test_psycopg.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ def test_manual_wrap_extension_types(self):
115115
# TypeError: argument 2 must be a connection, cursor or None
116116
extras.register_uuid(conn_or_curs=conn)
117117

118+
# NOTE: this will crash if it doesn't work.
119+
# _ext.register_default_json(conn)
120+
# TypeError: argument 2 must be a connection, cursor or None
121+
extras.register_default_json(conn)
122+
118123
def test_connect_factory(self):
119124
tracer = get_dummy_tracer()
120125

0 commit comments

Comments
 (0)