Skip to content

Commit ebebc19

Browse files
committed
Support psycopg3
1 parent 557e94b commit ebebc19

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

psqlextra/backend/schema.py

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

429429
with self.connection.cursor() as cursor:
430-
view_sql = cursor.mogrify(*meta.query).decode("utf-8")
430+
view_sql = cursor.mogrify(*meta.query)
431+
if isinstance(view_sql, bytes):
432+
view_sql = view_sql.decode("utf-8")
431433

432434
self.execute(sql % (self.quote_name(model._meta.db_table), view_sql))
433435

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+
"psycopg2>=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)

0 commit comments

Comments
 (0)