Skip to content

Commit b428fda

Browse files
authored
Support Django 4.2 + psycopg3 (#208)
1 parent c79a8ca commit b428fda

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

.circleci/config.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ executors:
77
type: string
88
docker:
99
- image: python:<< parameters.version >>-buster
10-
- image: postgres:11.0
10+
- image: postgres:12.0
1111
environment:
1212
POSTGRES_DB: 'psqlextra'
1313
POSTGRES_USER: 'psqlextra'
@@ -42,7 +42,6 @@ commands:
4242
environment:
4343
DATABASE_URL: 'postgres://psqlextra:psqlextra@localhost:5432/psqlextra'
4444

45-
4645
jobs:
4746
test-python36:
4847
executor:
@@ -78,7 +77,7 @@ jobs:
7877
extra: test
7978
- run-tests:
8079
pyversion: 38
81-
djversions: 20,21,22,30,31,32,40
80+
djversions: 20,21,22,30,31,32,40,41,42
8281

8382
test-python39:
8483
executor:
@@ -90,7 +89,7 @@ jobs:
9089
extra: test
9190
- run-tests:
9291
pyversion: 39
93-
djversions: 21,22,30,31,32,40
92+
djversions: 21,22,30,31,32,40,41,42
9493

9594
test-python310:
9695
executor:
@@ -102,7 +101,7 @@ jobs:
102101
extra: test
103102
- run-tests:
104103
pyversion: 310
105-
djversions: 21,22,30,31,32,40
104+
djversions: 21,22,30,31,32,40,41,42
106105
- store_test_results:
107106
path: reports
108107
- run:

psqlextra/backend/schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ def _create_view_model(self, sql: str, model: Model) -> None:
430430
meta = self._view_properties_for_model(model)
431431

432432
with self.connection.cursor() as cursor:
433-
view_sql = cursor.mogrify(*meta.query).decode("utf-8")
433+
view_sql = cursor.mogrify(*meta.query)
434+
if isinstance(view_sql, bytes):
435+
view_sql = view_sql.decode("utf-8")
434436

435437
self.execute(sql % (self.quote_name(model._meta.db_table), view_sql))
436438

psqlextra/compiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,13 @@ def execute_sql(self, return_id=False):
187187
rows.extend(cursor.fetchall())
188188
except ProgrammingError:
189189
pass
190+
description = cursor.description
190191

191192
# create a mapping between column names and column value
192193
return [
193194
{
194195
column.name: row[column_index]
195-
for column_index, column in enumerate(cursor.description)
196+
for column_index, column in enumerate(description)
196197
if row
197198
}
198199
for row in rows

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def run(self):
9595
"build==0.7.0",
9696
"twine==3.7.1",
9797
],
98+
"psycopg3": [
99+
"django>=4.2,<5.0",
100+
"psycopg[binary]>=3.0.0",
101+
],
98102
},
99103
cmdclass={
100104
"lint": create_command(

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def fake_app():
2929
def postgres_server_version(db) -> int:
3030
"""Gets the PostgreSQL server version."""
3131

32-
return connection.cursor().connection.server_version
32+
return connection.cursor().connection.info.server_version
3333

3434

3535
@pytest.fixture(autouse=True)

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py36-dj{20,21,22,30,31,32}, py37-dj{20,21,22,30,31,32}, py38-dj{20,21,22,30,31,32,40, 41}, py39-dj{21,22,30,31,32,40,41}, py310-dj{21,22,30,31,32,40,41}
2+
envlist = py36-dj{20,21,22,30,31,32}, py37-dj{20,21,22,30,31,32}, py38-dj{20,21,22,30,31,32,40,41,42}, py39-dj{21,22,30,31,32,40,41,42}, py310-dj{21,22,30,31,32,40,41,42}
33

44
[testenv]
55
deps =
@@ -11,6 +11,7 @@ deps =
1111
dj32: Django~=3.2.0
1212
dj40: Django~=4.0.0
1313
dj41: Django~=4.1.0
14+
dj42: .[psycopg3]
1415
.[test]
1516
setenv =
1617
DJANGO_SETTINGS_MODULE=settings

0 commit comments

Comments
 (0)