Skip to content

Commit 10c3d0d

Browse files
authored
Revert "Upgrade Silverstripe CMS to psycopg3 and stop shipping `psycopg2-bi…" (DataDog#20881)
This reverts commit 95b5d93.
1 parent 9c907f0 commit 10c3d0d

6 files changed

Lines changed: 24 additions & 14 deletions

File tree

.ddev/config.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ mmh3 = ['CC0-1.0']
7272
paramiko = ['LGPL-2.1-only']
7373
# https://github.com/psycopg/psycopg/blob/master/LICENSE.txt
7474
psycopg = ['LGPL-3.0-only']
75+
# https://github.com/psycopg/psycopg2/blob/master/LICENSE
76+
# https://github.com/psycopg/psycopg2/blob/master/doc/COPYING.LESSER
77+
psycopg2-binary = ['LGPL-3.0-only', 'BSD-3-Clause']
7578
# https://github.com/Legrandin/pycryptodome/blob/master/LICENSE.rst
7679
pycryptodomex = ['Unlicense', 'BSD-2-Clause']
7780
# https://github.com/mongodb/mongo-python-driver/blob/master/LICENSE
@@ -104,6 +107,7 @@ lxml = 'https://github.com/lxml/lxml'
104107
packaging = 'https://github.com/pypa/packaging'
105108
paramiko = 'https://github.com/paramiko/paramiko'
106109
protobuf = 'https://github.com/protocolbuffers/protobuf'
110+
psycopg2-binary = 'https://github.com/psycopg/psycopg2'
107111
pycryptodomex = 'https://github.com/Legrandin/pycryptodome'
108112
redis = 'https://github.com/redis/redis-py'
109113
requests = 'https://github.com/psf/requests'
@@ -158,6 +162,9 @@ exclude = [
158162
'aerospike', # v8+ breaks agent build.
159163
# https://github.com/DataDog/integrations-core/pull/16080
160164
'lxml',
165+
# We're not ready to switch to v3 of the postgres library, see:
166+
# https://github.com/DataDog/integrations-core/pull/15859
167+
'psycopg2-binary',
161168
'psutil',
162169
'pyvmomi', # 9+ has breaking changes
163170
'pymongo', # Upgrade from 4.8.0 to 4.10.1 causes "AttributeError: module 'pymongo' has no attribute 'mongo_client'"

LICENSE-3rdparty.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ prometheus-client,PyPI,Apache-2.0,Copyright 2015 The Prometheus Authors
4747
protobuf,PyPI,BSD-3-Clause,Copyright 2008 Google Inc. All rights reserved.
4848
psutil,PyPI,BSD-3-Clause,"Copyright (c) 2009, Jay Loden, Dave Daeschler, Giampaolo Rodola"
4949
psycopg,PyPI,LGPL-3.0-only,Copyright (C) 2020 The Psycopg Team
50+
psycopg2-binary,PyPI,BSD-3-Clause,Copyright 2013 Federico Di Gregorio
51+
psycopg2-binary,PyPI,LGPL-3.0-only,Copyright (C) 2013 Federico Di Gregorio
5052
pyOpenSSL,PyPI,Apache-2.0,Copyright The pyOpenSSL developers
5153
pyasn1,PyPI,BSD-3-Clause,"Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>"
5254
pycryptodomex,PyPI,BSD-2-Clause,Copyright 2014 Helder Eijs

agent_requirements.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ prometheus-client==0.22.1
3333
protobuf==6.31.1
3434
psutil==6.0.0
3535
psycopg[binary]==3.2.9
36+
psycopg2-binary==2.9.9
37+
psycopg[binary]==3.2.9
3638
pyasn1==0.4.8
3739
pycryptodomex==3.23.0
3840
pydantic==2.11.7

datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/licenses.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
'mmh3': ['CC0-1.0'],
5454
# https://github.com/paramiko/paramiko/blob/master/LICENSE
5555
'paramiko': ['LGPL-2.1-only'],
56+
# https://github.com/psycopg/psycopg2/blob/master/LICENSE
57+
# https://github.com/psycopg/psycopg2/blob/master/doc/COPYING.LESSER
58+
'psycopg2-binary': ['LGPL-3.0-only', 'BSD-3-Clause'],
5659
# https://github.com/psycopg/psycopg/blob/master/LICENSE.txt
5760
'psycopg': ['LGPL-3.0-only'],
5861
# https://github.com/psycopg/psycopg/blob/master/psycopg_pool/LICENSE.txt
@@ -164,6 +167,7 @@
164167
'packaging': 'https://github.com/pypa/packaging',
165168
'paramiko': 'https://github.com/paramiko/paramiko',
166169
'protobuf': 'https://github.com/protocolbuffers/protobuf',
170+
'psycopg2-binary': 'https://github.com/psycopg/psycopg2',
167171
'psycopg': 'https://github.com/psycopg/psycopg',
168172
'pycryptodomex': 'https://github.com/Legrandin/pycryptodome',
169173
'redis': 'https://github.com/redis/redis-py',

silverstripe_cms/datadog_checks/silverstripe_cms/database_client.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44

5-
import psycopg
5+
import psycopg2
6+
import psycopg2.extras
67
import pymysql
7-
from psycopg import ClientCursor
8-
from psycopg.rows import dict_row
98

109
from datadog_checks.base.errors import ConfigurationError
1110

@@ -45,23 +44,19 @@ def create_connection(self) -> None:
4544
)
4645
else:
4746
# PostgreSQL connection settings
48-
self.connection = psycopg.connect(
47+
self.connection = psycopg2.connect(
4948
host=self.db_host,
5049
port=self.db_port,
5150
user=self.db_username,
5251
password=self.db_password,
5352
dbname=self.db_name,
54-
cursor_factory=ClientCursor,
53+
cursor_factory=psycopg2.extras.DictCursor,
5554
connect_timeout=DB_CONNECTION_TIMEOUT_IN_SECONDS,
56-
autocommit=True,
5755
)
5856
message = f"Successfully authenticated with the {self.db_type} database."
5957
self.log.info(LOG_TEMPLATE.format(host=self.db_host, message=message))
60-
if self.db_type == MYSQL:
61-
self.cursor = self.connection.cursor()
62-
else:
63-
self.cursor = self.connection.cursor(row_factory=dict_row)
64-
except (pymysql.Error, psycopg.Error) as db_err:
58+
self.cursor = self.connection.cursor()
59+
except (pymysql.Error, psycopg2.Error) as db_err:
6560
err_message = (
6661
f"Authentication failed for provided credentials. Please check the provided credentials."
6762
f" | Error={db_err}."
@@ -75,7 +70,7 @@ def close_connection(self) -> None:
7570
self.connection.close()
7671
message = "Connection closed successfully."
7772
self.log.info(LOG_TEMPLATE.format(host=self.db_host, message=message))
78-
except (pymysql.Error, psycopg.Error) as db_err:
73+
except (pymysql.Error, psycopg2.Error) as db_err:
7974
err_message = f"Error occurred while closing the connection. | Error={db_err}."
8075
self.log.error(LOG_TEMPLATE.format(host=self.db_host, message=err_message))
8176

@@ -103,6 +98,6 @@ def execute_query(self, query: str) -> list:
10398
try:
10499
self.cursor.execute(query)
105100
return self.cursor.fetchall()
106-
except (pymysql.Error, psycopg.Error) as db_err:
101+
except (pymysql.Error, psycopg2.Error) as db_err:
107102
err_message = f"Error occurred while executing query: {query}. | Error={db_err}."
108103
self.log.error(LOG_TEMPLATE.format(host=self.db_host, message=err_message))

silverstripe_cms/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dynamic = [
3737

3838
[project.optional-dependencies]
3939
deps = [
40-
"psycopg[binary]==3.2.9",
40+
"psycopg2-binary==2.9.9",
4141
"PyMySQL==1.1.1"
4242
]
4343

0 commit comments

Comments
 (0)