Skip to content

Commit a04bfb6

Browse files
author
Emanuele Palazzetti
committed
[psycopg2] add support for version 2.4
1 parent c1e427b commit a04bfb6

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ jobs:
579579
keys:
580580
- tox-cache-pycopg-{{ checksum "tox.ini" }}
581581
- run: tox -e 'wait' postgres
582-
- run: tox -e '{py27,py34,py35,py36}-psycopg2{25,26,27}' --result-json /tmp/psycopg.results
582+
- run: tox -e '{py27,py34,py35,py36}-psycopg2{24,25,26,27}' --result-json /tmp/psycopg.results
583583
- persist_to_workspace:
584584
root: /tmp
585585
paths:

ddtrace/contrib/psycopg/patch.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,15 @@ def prepare(self, *args, **kwargs):
124124
(psycopg2._psycopg.register_type,
125125
psycopg2._psycopg, 'register_type',
126126
_extensions_register_type),
127-
(psycopg2._json.register_type,
128-
psycopg2._json, 'register_type',
129-
_extensions_register_type),
130127
(psycopg2.extensions.adapt,
131128
psycopg2.extensions, 'adapt',
132129
_extensions_adapt),
133130
]
131+
132+
# `_json` attribute is only available for psycopg >= 2.5
133+
if getattr(psycopg2, '_json', None):
134+
_psycopg2_extensions += [
135+
(psycopg2._json.register_type,
136+
psycopg2._json, 'register_type',
137+
_extensions_register_type),
138+
]

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ We officially support Python 2.7, 3.4 and above.
567567
+-----------------+--------------------+
568568
| mysqlclient | >= 1.3 |
569569
+-----------------+--------------------+
570-
| psycopg2 | >= 2.5 |
570+
| psycopg2 | >= 2.4 |
571571
+-----------------+--------------------+
572572
| pylibmc | >= 1.4 |
573573
+-----------------+--------------------+

tests/contrib/psycopg/test_psycopg.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from psycopg2 import _psycopg
77
from psycopg2 import extensions
88
from psycopg2 import extras
9+
10+
from unittest import skipIf
911
from nose.tools import eq_, ok_
1012

1113
# project
@@ -18,6 +20,7 @@
1820
from tests.test_tracer import get_dummy_tracer
1921

2022

23+
PSYCOPG_VERSION = tuple(map(int, psycopg2.__version__.split()[0].split('.')))
2124
TEST_PORT = str(POSTGRES_CONFIG['port'])
2225

2326

@@ -84,10 +87,10 @@ def assert_conn_is_traced(self, tracer, db, service):
8487
eq_(span.meta["out.port"], TEST_PORT)
8588
eq_(span.span_type, "sql")
8689

90+
@skipIf(PSYCOPG_VERSION < (2, 5), 'context manager not available in psycopg2==2.4')
8791
def test_cursor_ctx_manager(self):
8892
# ensure cursors work with context managers
8993
# https://github.com/DataDog/dd-trace-py/issues/228
90-
9194
conn, tracer = self._get_conn_and_tracer()
9295
t = type(conn.cursor())
9396
with conn.cursor() as cur:
@@ -110,6 +113,7 @@ def test_disabled_execute(self):
110113
conn.cursor().execute("select 'blah'")
111114
assert not tracer.writer.pop()
112115

116+
@skipIf(PSYCOPG_VERSION < (2, 5), '_json is not available in psycopg2==2.4')
113117
def test_manual_wrap_extension_types(self):
114118
conn, _ = self._get_conn_and_tracer()
115119
# NOTE: this will crash if it doesn't work.

tox.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ envlist =
6464
{py27,py34,py35,py36}-pyramid-autopatch{17,18,19}-webtest
6565
{py27,py34,py35,py36}-requests{208,209,210,211,212,213}
6666
{py27,py34,py35,py36}-sqlalchemy{10,11}-psycopg2{27}-mysqlconnector{21}
67-
{py27,py34,py35,py36}-psycopg2{25,26,27}
67+
{py27,py34,py35,py36}-psycopg2{24,25,26,27}
6868
{py34,py35,py36}-aiobotocore{02,03,04}
6969
{py34,py35,py36}-aiopg{012,013}
7070
{py27,py34,py35,py36}-redis{26,27,28,29,210}
@@ -195,6 +195,7 @@ deps =
195195
pyramid-autopatch17: pyramid>=1.7,<1.8
196196
pyramid-autopatch18: pyramid>=1.8,<1.9
197197
pyramid-autopatch19: pyramid>=1.9,<1.10
198+
psycopg224: psycopg2>=2.4,<2.5
198199
psycopg225: psycopg2>=2.5,<2.6
199200
psycopg226: psycopg2>=2.6,<2.7
200201
psycopg227: psycopg2>=2.7,<2.8
@@ -265,7 +266,7 @@ commands =
265266
pyramid{17,18,19}: nosetests {posargs} tests/contrib/pyramid/test_pyramid.py
266267
pyramid-autopatch{17,18,19}: ddtrace-run nosetests {posargs} tests/contrib/pyramid/test_pyramid_autopatch.py
267268
mongoengine: nosetests {posargs} tests/contrib/mongoengine
268-
psycopg2{25,26,27}: nosetests {posargs} tests/contrib/psycopg
269+
psycopg2{24,25,26,27}: nosetests {posargs} tests/contrib/psycopg
269270
py{34}-aiopg{012,013}: nosetests {posargs} --exclude=".*(test_aiopg_35).*" tests/contrib/aiopg
270271
py{35,36}-aiopg{012,013}: nosetests {posargs} tests/contrib/aiopg
271272
redis{26,27,28,29,210}: nosetests {posargs} tests/contrib/redis

0 commit comments

Comments
 (0)