Skip to content

Commit 2b67964

Browse files
committed
issue2551040: New release of psycopg2 drops support for psycopg1
First try at suport for psycopg2. Change .travis.yml to install newest psycopg2 without psycopg1 support.
1 parent dc6baea commit 2b67964

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ before_install:
6767

6868
install:
6969
- pip install mysqlclient==1.3.13
70-
- pip install psycopg2==2.7.7
70+
- pip install psycopg2
7171
- pip install gpg pytz whoosh
7272
- pip install pytest-cov codecov
7373

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ Fixed:
138138
code to make sure valid backend database is set. Remove config.ini
139139
from templates to make sure that roundup-admin install writes a new
140140
default config.ini based on configuration.py.
141+
- issue2551040: New release of psycopg2 drops support for psycopg1 -
142+
need to rewrite. Now uses psycopg2 throughout. (John Rouillard)
141143

142144
2018-07-13 1.6.0
143145

roundup/backends/back_postgresql.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# under the same terms as Python, so long as this copyright message and
55
# disclaimer are retained in their original form.
66
#
7-
'''Postgresql backend via psycopg for Roundup.'''
7+
'''Postgresql backend via psycopg2 for Roundup.'''
88
__docformat__ = 'restructuredtext'
99

1010
import os, shutil, time
@@ -13,13 +13,13 @@
1313
ISOLATION_LEVEL_REPEATABLE_READ = None
1414
ISOLATION_LEVEL_SERIALIZABLE = None
1515

16-
from psycopg2 import psycopg1 as psycopg
16+
import psycopg2
1717
from psycopg2.extensions import QuotedString
1818
from psycopg2.extensions import ISOLATION_LEVEL_READ_UNCOMMITTED
1919
from psycopg2.extensions import ISOLATION_LEVEL_READ_COMMITTED
2020
from psycopg2.extensions import ISOLATION_LEVEL_REPEATABLE_READ
2121
from psycopg2.extensions import ISOLATION_LEVEL_SERIALIZABLE
22-
from psycopg2.psycopg1 import ProgrammingError
22+
from psycopg2 import ProgrammingError
2323
from psycopg2.extensions import TransactionRollbackError
2424

2525
import logging
@@ -66,15 +66,15 @@ def db_command(config, command, database='postgres'):
6666
fail by conflicting with another user.
6767
6868
Since PostgreSQL version 8.1 there is a database "postgres",
69-
before "template1" seems to habe been used, so we fall back to it.
69+
before "template1" seems to have been used, so we fall back to it.
7070
Compare to issue2550543.
7171
'''
7272
template1 = connection_dict(config)
7373
template1['database'] = database
7474

7575
try:
76-
conn = psycopg.connect(**template1)
77-
except psycopg.OperationalError as message:
76+
conn = psycopg2.connect(**template1)
77+
except psycopg2.OperationalError as message:
7878
if str(message).find('database "postgres" does not exist') >= 0:
7979
return db_command(config, command, database='template1')
8080
raise hyperdb.DatabaseError(message)
@@ -97,7 +97,7 @@ def pg_command(cursor, command):
9797
'''
9898
try:
9999
cursor.execute(command)
100-
except psycopg.DatabaseError as err:
100+
except psycopg2.DatabaseError as err:
101101
response = str(err).split('\n')[0]
102102
if "FATAL" not in response :
103103
msgs = (
@@ -115,7 +115,7 @@ def db_exists(config):
115115
"""Check if database already exists"""
116116
db = connection_dict(config, 'database')
117117
try:
118-
conn = psycopg.connect(**db)
118+
conn = psycopg2.connect(**db)
119119
conn.close()
120120
return 1
121121
except:
@@ -156,8 +156,8 @@ def sql_open_connection(self):
156156
logging.getLogger('roundup.hyperdb').info(
157157
'open database %r'%db['database'])
158158
try:
159-
conn = psycopg.connect(**db)
160-
except psycopg.OperationalError as message:
159+
conn = psycopg2.connect(**db)
160+
except psycopg2.OperationalError as message:
161161
raise hyperdb.DatabaseError(message)
162162

163163
cursor = conn.cursor()
@@ -245,7 +245,7 @@ def __repr__(self):
245245
return '<roundpsycopgsql 0x%x>' % id(self)
246246

247247
def sql_stringquote(self, value):
248-
''' psycopg.QuotedString returns a "buffer" object with the
248+
''' psycopg2.QuotedString returns a "buffer" object with the
249249
single-quotes around it... '''
250250
return str(QuotedString(str(value)))[1:-1]
251251

test/test_postgresql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
reason='Skipping PostgreSQL tests: backend not available'))
3535
else:
3636
try:
37-
from roundup.backends.back_postgresql import psycopg, db_command
37+
from roundup.backends.back_postgresql import psycopg2, db_command
3838
db_command(config, 'select 1')
3939
skip_postgresql = lambda func, *args, **kwargs: func
4040
except( DatabaseError ) as msg:
@@ -110,7 +110,7 @@ def tearDown(self):
110110
try:
111111
self.db1.close()
112112
self.db2.close()
113-
except psycopg.InterfaceError as exc:
113+
except psycopg2.InterfaceError as exc:
114114
if 'connection already closed' in str(exc): pass
115115
else: raise
116116
ClassicInitBase.tearDown(self)

0 commit comments

Comments
 (0)