From e6ab40d9f0dbcc70be657e39866d5bafab1b7614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=C5=9Aliwi=C5=84ski?= Date: Wed, 16 Nov 2022 21:28:22 +0100 Subject: [PATCH 1/3] Add support for Django 4.1 * Strip IDENTITY related suffixes auto fields are getting on Django 4.1. These suffixes are upsetting redshift. --- .github/workflows/test.yml | 4 +++- .gitignore | 1 + django_redshift_backend/base.py | 4 ++++ doc/index.rst | 2 +- setup.cfg | 1 + tox.ini | 1 + 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4837606..336cd81 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,10 +11,12 @@ jobs: max-parallel: 5 matrix: python-version: ['3.7', '3.8', '3.9', '3.10'] - django-version: ['3.2', '4.0'] + django-version: ['3.2', '4.0', '4.1'] exclude: - django-version: '4.0' python-version: '3.7' + - django-version: '4.1' + python-version: '3.7' include: - django-version: 'main' python-version: '3.9' diff --git a/.gitignore b/.gitignore index b5e9346..fd8a5d0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ doc/_build/ coverage.xml **/.env examples/**/migrations/* +.idea/ \ No newline at end of file diff --git a/django_redshift_backend/base.py b/django_redshift_backend/base.py index df6cf2b..2e1ff33 100644 --- a/django_redshift_backend/base.py +++ b/django_redshift_backend/base.py @@ -1092,6 +1092,10 @@ class DatabaseWrapper(BasePGDatabaseWrapper): data_types = deepcopy(BasePGDatabaseWrapper.data_types) data_types.update(redshift_data_types) + # Clear suffixes to rid of PostgreSQLs GENERATED BY DEFAULT AS IDENTITY that upset Redshift. + # Takes effect on Django>=4.1. Older version have this attribute empty + data_types_suffix = {} + def __init__(self, *args, **kwargs): super(DatabaseWrapper, self).__init__(*args, **kwargs) diff --git a/doc/index.rst b/doc/index.rst index 24742bb..93ded67 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -44,7 +44,7 @@ Support versions This product is tested with: * Python-3.7, 3.8, 3.9, 3.10 -* Django-3.2, 4.0 +* Django-3.2, 4.0, 4.1 License ======= diff --git a/setup.cfg b/setup.cfg index c4371f0..2d5c46c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,6 +21,7 @@ classifiers = Framework :: Django Framework :: Django :: 3.2 Framework :: Django :: 4.0 + Framework :: Django :: 4.1 Intended Audience :: Developers Environment :: Plugins Topic :: Software Development :: Libraries :: Python Modules diff --git a/tox.ini b/tox.ini index 793d3db..6f3c016 100644 --- a/tox.ini +++ b/tox.ini @@ -17,6 +17,7 @@ python = DJANGO = 3.2: dj32 4.0: dj40 + 4.1: dj41 main: djmain [testenv] From 2042b7259339eb7881cae9e169929a38674e331b Mon Sep 17 00:00:00 2001 From: shimizukawa Date: Sat, 26 Nov 2022 04:47:18 +0000 Subject: [PATCH 2/3] add dj41 test for tox.ini --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 6f3c016..a5916d9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist = py37-dj32 - py{38,39,310}-dj{32,40,main} + py{38,39,310}-dj{32,40,41,main} flake8 check skipsdist = True @@ -29,6 +29,7 @@ deps = mock>=2.0 dj32: Django>=3.2,<3.3 dj40: Django>=4.0,<4.1 + dj41: Django>=4.1,<4.2 djmain: https://github.com/django/django/archive/main.tar.gz setenv = DJANGO_SETTINGS_MODULE = settings From a7b1dc725d75b5ea205e7cb0e991dec18243689a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=C5=9Aliwi=C5=84ski?= Date: Thu, 1 Dec 2022 16:49:12 +0100 Subject: [PATCH 3/3] Use old get_field_type --- django_redshift_backend/base.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/django_redshift_backend/base.py b/django_redshift_backend/base.py index 2e1ff33..cb0cf0a 100644 --- a/django_redshift_backend/base.py +++ b/django_redshift_backend/base.py @@ -1083,9 +1083,22 @@ def get_table_list(self, cursor): """) return [TableInfo(*row) for row in cursor.fetchall() if row[0] not in self.ignored_tables] + def get_field_type(self, data_type, description): + # instead of calling a parent method, doing directly what grapndparent class does. + field_type = self.data_types_reverse[data_type] + if description.default and "nextval" in description.default: + if field_type == "IntegerField": + return "AutoField" + elif field_type == "BigIntegerField": + return "BigAutoField" + elif field_type == "SmallIntegerField": + return "SmallAutoField" + return field_type + class DatabaseWrapper(BasePGDatabaseWrapper): vendor = 'redshift' + display_name = "AWS Redshift" SchemaEditorClass = DatabaseSchemaEditor