From faab0c5bbcb5f60794b0df6ab6aba167ab81c330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20=C5=A0nuderl?= Date: Wed, 5 Apr 2023 16:11:58 +0200 Subject: [PATCH 1/6] Support psycopg3 --- psqlextra/backend/schema.py | 4 +++- psqlextra/compiler.py | 3 ++- setup.py | 4 ++++ tests/conftest.py | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/psqlextra/backend/schema.py b/psqlextra/backend/schema.py index b59ed617..413f039d 100644 --- a/psqlextra/backend/schema.py +++ b/psqlextra/backend/schema.py @@ -430,7 +430,9 @@ def _create_view_model(self, sql: str, model: Model) -> None: meta = self._view_properties_for_model(model) with self.connection.cursor() as cursor: - view_sql = cursor.mogrify(*meta.query).decode("utf-8") + view_sql = cursor.mogrify(*meta.query) + if isinstance(view_sql, bytes): + view_sql = view_sql.decode("utf-8") self.execute(sql % (self.quote_name(model._meta.db_table), view_sql)) diff --git a/psqlextra/compiler.py b/psqlextra/compiler.py index ee414bfd..be96e50d 100644 --- a/psqlextra/compiler.py +++ b/psqlextra/compiler.py @@ -187,12 +187,13 @@ def execute_sql(self, return_id=False): rows.extend(cursor.fetchall()) except ProgrammingError: pass + description = cursor.description # create a mapping between column names and column value return [ { column.name: row[column_index] - for column_index, column in enumerate(cursor.description) + for column_index, column in enumerate(description) if row } for row in rows diff --git a/setup.py b/setup.py index 281be89d..6b099a3c 100644 --- a/setup.py +++ b/setup.py @@ -95,6 +95,10 @@ def run(self): "build==0.7.0", "twine==3.7.1", ], + "psycopg3": [ + "django>=4.2,<5.0", + "psycopg2>=3.0.0", + ], }, cmdclass={ "lint": create_command( diff --git a/tests/conftest.py b/tests/conftest.py index f90692af..387edd3b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -29,7 +29,7 @@ def fake_app(): def postgres_server_version(db) -> int: """Gets the PostgreSQL server version.""" - return connection.cursor().connection.server_version + return connection.cursor().connection.info.server_version @pytest.fixture(autouse=True) From 53f2b59f3c2ce7277e2ffd377a8a515ba61014a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20=C5=A0nuderl?= Date: Thu, 6 Apr 2023 10:19:49 +0200 Subject: [PATCH 2/6] Tox --- .circleci/config.yml | 12 +++++++++--- tox.ini | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e494f4bd..79dc598b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -42,6 +42,12 @@ commands: environment: DATABASE_URL: 'postgres://psqlextra:psqlextra@localhost:5432/psqlextra' + - run: + name: Run tests psycopg3 + command: tox -e 'py<< parameters.pyversion >>-dj{<< parameters.djversions >>}' + environment: + DATABASE_URL: 'postgres://psqlextra:psqlextra@localhost:5432/psqlextra' + jobs: test-python36: @@ -78,7 +84,7 @@ jobs: extra: test - run-tests: pyversion: 38 - djversions: 20,21,22,30,31,32,40 + djversions: 20,21,22,30,31,32,40,42 test-python39: executor: @@ -90,7 +96,7 @@ jobs: extra: test - run-tests: pyversion: 39 - djversions: 21,22,30,31,32,40 + djversions: 21,22,30,31,32,40,42 test-python310: executor: @@ -102,7 +108,7 @@ jobs: extra: test - run-tests: pyversion: 310 - djversions: 21,22,30,31,32,40 + djversions: 21,22,30,31,32,40,42 - store_test_results: path: reports - run: diff --git a/tox.ini b/tox.ini index 26be5d15..422f53ce 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -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} +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} [testenv] deps = @@ -11,6 +11,7 @@ deps = dj32: Django~=3.2.0 dj40: Django~=4.0.0 dj41: Django~=4.1.0 + dj42: Django~=4.2.0 psycopg~=3.1.0 .[test] setenv = DJANGO_SETTINGS_MODULE=settings From d02810b322768c651c868e352010f1673087a552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20=C5=A0nuderl?= Date: Thu, 6 Apr 2023 08:48:55 +0200 Subject: [PATCH 3/6] Set up tests --- .circleci/config.yml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 79dc598b..bdc44e42 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ executors: type: string docker: - image: python:<< parameters.version >>-buster - - image: postgres:11.0 + - image: postgres:12.0 environment: POSTGRES_DB: 'psqlextra' POSTGRES_USER: 'psqlextra' diff --git a/setup.py b/setup.py index 6b099a3c..a7f6b8f0 100644 --- a/setup.py +++ b/setup.py @@ -97,7 +97,7 @@ def run(self): ], "psycopg3": [ "django>=4.2,<5.0", - "psycopg2>=3.0.0", + "psycopg[binary]>=3.0.0", ], }, cmdclass={ From f5b02c94f6eefd056ba16afdc3bf9a8cdfa8345e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20=C5=A0nuderl?= Date: Thu, 6 Apr 2023 10:21:31 +0200 Subject: [PATCH 4/6] fix --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 422f53ce..7cf24e55 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,7 @@ deps = dj32: Django~=3.2.0 dj40: Django~=4.0.0 dj41: Django~=4.1.0 - dj42: Django~=4.2.0 psycopg~=3.1.0 + dj42: .[psycopg3] .[test] setenv = DJANGO_SETTINGS_MODULE=settings From 04be04bceecbdad738aa06a4cfc714bce71e49ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20=C5=A0nuderl?= Date: Thu, 6 Apr 2023 13:29:12 +0200 Subject: [PATCH 5/6] Remove unused change --- .circleci/config.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bdc44e42..6dc31d37 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -42,13 +42,6 @@ commands: environment: DATABASE_URL: 'postgres://psqlextra:psqlextra@localhost:5432/psqlextra' - - run: - name: Run tests psycopg3 - command: tox -e 'py<< parameters.pyversion >>-dj{<< parameters.djversions >>}' - environment: - DATABASE_URL: 'postgres://psqlextra:psqlextra@localhost:5432/psqlextra' - - jobs: test-python36: executor: From a6142ff48f730bf5d1059c95a0e2444c0b74db77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20=C5=A0nuderl?= Date: Thu, 6 Apr 2023 13:31:07 +0200 Subject: [PATCH 6/6] Run tests on django 4.1 too --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6dc31d37..7f245a40 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -77,7 +77,7 @@ jobs: extra: test - run-tests: pyversion: 38 - djversions: 20,21,22,30,31,32,40,42 + djversions: 20,21,22,30,31,32,40,41,42 test-python39: executor: @@ -89,7 +89,7 @@ jobs: extra: test - run-tests: pyversion: 39 - djversions: 21,22,30,31,32,40,42 + djversions: 21,22,30,31,32,40,41,42 test-python310: executor: @@ -101,7 +101,7 @@ jobs: extra: test - run-tests: pyversion: 310 - djversions: 21,22,30,31,32,40,42 + djversions: 21,22,30,31,32,40,41,42 - store_test_results: path: reports - run: