Skip to content

Commit

Permalink
chore: add compatibility with Psycopg 3
Browse files Browse the repository at this point in the history
  • Loading branch information
hartungstenio committed May 30, 2023
1 parent 5a853e6 commit e76ec63
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 10 additions & 1 deletion drf_extra_fields/compat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import django

try:
from django.contrib.postgres.fields import FloatRangeField
except ImportError:
FloatRangeField = None

try:
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
if django.VERSION >= (4, 2):
try:
from psycopg.types.range import DateRange, NumericRange
from psycopg.types.range import TimestamptzRange as DateTimeTZRange
except ImportError:
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
else:
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
except ImportError:
DateRange = None
DateTimeTZRange = None
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Pillow >= 6.2.1
pytest-django
pytest-cov
psycopg2-binary
psycopg[binary]
flake8
12 changes: 9 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ python =
[tox]
envlist =
flake8,
py{37,38,39,310}-drf3-django{22,32}
py{38,39,310,311}-drf3-django{40,41,42}
py{37,38,39,310}-drf3-django{22,32}-psycopg2
py{38,39,310,311}-drf3-django{40,41}-psycopg2
py{38,39,310,311}-drf3-django42-psycopg{2,3}

[testenv]
deps =
Expand All @@ -20,7 +21,12 @@ deps =
django41: Django>=4.1,<4.2
django42: Django>=4.2,<4.3
drf3: djangorestframework>=3
-r requirements_dev.txt
psycopg2: psycopg2-binary
psycopg3: psycopg[binary]

Pillow >= 6.2.1
pytest-django
pytest-cov
commands =
py.test {posargs} --cov-report=xml --cov

Expand Down

0 comments on commit e76ec63

Please sign in to comment.