diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index fb53c1c..3ff4a96 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -13,19 +13,23 @@ jobs: matrix: python-version: ["3.5", "3.6", "3.7", "3.8", "3.9"] postgres-version: ["9.4", "9.5", "9.6", "10", "11", "12"] - django-version: ["1.8", "1.9", "1.10", "1.11", "2.0", "2.1", "2.2", "3.0", "3.1"] + django-version: ["1.8", "1.9", "1.10", "1.11", "2.0", "2.1", "2.2", "3.0", "3.1", "3.2"] exclude: # Django 3.0+ doesn't support python 3.5 - python-version: "3.5" django-version: "3.0" - python-version: "3.5" django-version: "3.1" + - python-version: "3.5" + django-version: "3.2" # Django 3.0+ doesn't support PostgreSQL 9.4 - django-version: "3.0" postgres-version: "9.4" - django-version: "3.1" postgres-version: "9.4" + - django-version: "3.2" + postgres-version: "9.4" # python 3.6+ has deprecated issue with django before 1.11 # https://stackoverflow.com/questions/41343263/provide-classcell-example-for-python-3-6-metaclass\ diff --git a/requirements-test.txt b/requirements-test.txt index fb48073..ea89891 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,5 +1,8 @@ django>=1.7 -psycopg2-binary + +# FIXME On later versions I get strange error 'database connection isn't set to UTC' +psycopg2-binary<=2.8.6 + pytz; python_version < '3.3' typing; python_version < '3.5' diff --git a/setup.py b/setup.py index 942d010..a55db98 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name='django-pg-bulk-update', - version='3.4.2', + version='3.4.3', packages=['django_pg_bulk_update'], package_dir={'': 'src'}, url='https://github.com/M1hacka/django-pg-bulk-update', diff --git a/src/django_pg_bulk_update/compatibility.py b/src/django_pg_bulk_update/compatibility.py index 1a00ef3..43340c2 100644 --- a/src/django_pg_bulk_update/compatibility.py +++ b/src/django_pg_bulk_update/compatibility.py @@ -10,7 +10,13 @@ from django.db import connection, connections, models, migrations from django.db.models import Model, Field, BigIntegerField, IntegerField -from .types import TDatabase + +try: + # For django 3.2+ + from django.utils.connection import ConnectionProxy +except ImportError: + # For django before 3.2 + from django.db import DefaultConnectionProxy as ConnectionProxy # six.string_types replacement in order to remove dependency @@ -139,7 +145,7 @@ def get_postgres_version(using=None, as_tuple=True): def get_field_db_type(field, conn): - # type: (models.Field, TDatabase) -> str + # type: (models.Field, ConnectionProxy) -> str """ Get database field type used for this field. :param field: django.db.models.Field instance diff --git a/src/django_pg_bulk_update/manager.py b/src/django_pg_bulk_update/manager.py index e21b8c6..5117bdc 100644 --- a/src/django_pg_bulk_update/manager.py +++ b/src/django_pg_bulk_update/manager.py @@ -16,14 +16,14 @@ class CustomManager(models.Manager, BulkUpdateManagerMixin): class TestModel(models.Model): objects = CustomManager() """ -from django.db import models +from logging import getLogger from typing import Optional, Iterable, Union +from django.db import models from django.db.models.manager import BaseManager -from logging import getLogger -from .types import TUpdateValues, TFieldNames, TSetFunctions, TOperators from .query import bulk_update, bulk_update_or_create, bulk_create +from .types import TUpdateValues, TFieldNames, TSetFunctions, TOperators logger = getLogger('django-pg-bulk-update') diff --git a/src/django_pg_bulk_update/query.py b/src/django_pg_bulk_update/query.py index 3007195..7297fbf 100644 --- a/src/django_pg_bulk_update/query.py +++ b/src/django_pg_bulk_update/query.py @@ -20,7 +20,6 @@ TSetFunctionsValid, TDatabase, FieldDescriptor, AbstractFieldFormatter from .utils import batched_operation, is_auto_set_field - __all__ = ['pdnf_clause', 'bulk_update', 'bulk_update_or_create', 'bulk_create'] logger = getLogger('django-pg-bulk-update') diff --git a/src/django_pg_bulk_update/types.py b/src/django_pg_bulk_update/types.py index 58aacf1..68d8e06 100644 --- a/src/django_pg_bulk_update/types.py +++ b/src/django_pg_bulk_update/types.py @@ -1,8 +1,9 @@ from typing import Iterable, Union, Dict, Tuple, Any, Optional, Type -from django.db import DefaultConnectionProxy from django.db.models import Model, Field +from .compatibility import ConnectionProxy + TFieldNames = Union[str, Iterable[str]] TOperator = Union[str, 'AbstractClauseOperator'] # noqa: F821 @@ -14,7 +15,7 @@ TSetFunction = Union[str, 'AbstractSetFunction'] # noqa: F821 TSetFunctions = Optional[Dict[str, TSetFunction]] TSetFunctionsValid = Tuple['FieldDescriptor'] -TDatabase = Union[DefaultConnectionProxy] +TDatabase = Union[ConnectionProxy] class FieldDescriptor(object): diff --git a/src/django_pg_bulk_update/utils.py b/src/django_pg_bulk_update/utils.py index 3222e62..10704e6 100644 --- a/src/django_pg_bulk_update/utils.py +++ b/src/django_pg_bulk_update/utils.py @@ -3,11 +3,11 @@ """ import logging from time import sleep +from typing import TypeVar, Set, Any, Tuple, Iterable, Callable, Optional, List from django.core.exceptions import FieldError from django.db.models import Field from django.db.models.sql.subqueries import UpdateQuery -from typing import TypeVar, Set, Any, Tuple, Iterable, Callable, Optional, List from .compatibility import hstore_serialize, hstore_available, get_field_db_type, import_pg_field_or_dummy from .types import TDatabase