Skip to content

Commit

Permalink
Merge pull request #74 from M1ha-Shvn/django-3.2-compat
Browse files Browse the repository at this point in the history
Fixed django 3.2 compatibility
  • Loading branch information
M1ha-Shvn authored Jul 6, 2021
2 parents 0076c9a + dc6e173 commit dd42972
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 12 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
5 changes: 4 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 8 additions & 2 deletions src/django_pg_bulk_update/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/django_pg_bulk_update/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
1 change: 0 additions & 1 deletion src/django_pg_bulk_update/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
5 changes: 3 additions & 2 deletions src/django_pg_bulk_update/types.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/django_pg_bulk_update/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dd42972

Please sign in to comment.