Skip to content

Commit 333f1ff

Browse files
authored
Confirmed support for Django 4.1. (encode#8498)
1 parent 7069083 commit 333f1ff

File tree

8 files changed

+21
-12
lines changed

8 files changed

+21
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ There is a live example API for testing purposes, [available here][sandbox].
5555
# Requirements
5656

5757
* Python (3.6, 3.7, 3.8, 3.9, 3.10)
58-
* Django (2.2, 3.0, 3.1, 3.2, 4.0)
58+
* Django (2.2, 3.0, 3.1, 3.2, 4.0, 4.1)
5959

6060
We **highly recommend** and only officially support the latest patch release of
6161
each Python and Django series.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ continued development by **[signing up for a paid plan][funding]**.
8686
REST framework requires the following:
8787

8888
* Python (3.6, 3.7, 3.8, 3.9, 3.10)
89-
* Django (2.2, 3.0, 3.1, 3.2, 4.0)
89+
* Django (2.2, 3.0, 3.1, 3.2, 4.0, 4.1)
9090

9191
We **highly recommend** and only officially support the latest patch release of
9292
each Python and Django series.

rest_framework/fields.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from django.utils.encoding import is_protected_type, smart_str
2828
from django.utils.formats import localize_input, sanitize_separators
2929
from django.utils.ipv6 import clean_ipv6_address
30-
from django.utils.timezone import utc
3130
from django.utils.translation import gettext_lazy as _
3231
from pytz.exceptions import InvalidTimeError
3332

@@ -1190,7 +1189,7 @@ def enforce_timezone(self, value):
11901189
except InvalidTimeError:
11911190
self.fail('make_aware', timezone=field_timezone)
11921191
elif (field_timezone is None) and timezone.is_aware(value):
1193-
return timezone.make_naive(value, utc)
1192+
return timezone.make_naive(value, datetime.timezone.utc)
11941193
return value
11951194

11961195
def default_timezone(self):

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def get_version(package):
9494
'Framework :: Django :: 3.1',
9595
'Framework :: Django :: 3.2',
9696
'Framework :: Django :: 4.0',
97+
'Framework :: Django :: 4.1',
9798
'Intended Audience :: Developers',
9899
'License :: OSI Approved :: BSD License',
99100
'Operating System :: OS Independent',

tests/test_encoders.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
from datetime import date, datetime, timedelta
1+
from datetime import date, datetime, timedelta, timezone
22
from decimal import Decimal
33
from uuid import uuid4
44

55
import pytest
66
from django.test import TestCase
7-
from django.utils.timezone import utc
87

98
from rest_framework.compat import coreapi
109
from rest_framework.utils.encoders import JSONEncoder
1110
from rest_framework.utils.serializer_helpers import ReturnList
1211

12+
utc = timezone.utc
13+
1314

1415
class MockList:
1516
def tolist(self):

tests/test_fields.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
from django.core.exceptions import ValidationError as DjangoValidationError
1010
from django.http import QueryDict
1111
from django.test import TestCase, override_settings
12-
from django.utils.timezone import activate, deactivate, override, utc
12+
from django.utils.timezone import activate, deactivate, override
1313

1414
import rest_framework
1515
from rest_framework import exceptions, serializers
1616
from rest_framework.fields import (
1717
BuiltinSignatureError, DjangoImageField, is_simple_callable
1818
)
1919

20+
utc = datetime.timezone.utc
21+
2022
# Tests for helper functions.
2123
# ---------------------------
2224

tests/test_model_serializer.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tempfile
1313
from collections import OrderedDict
1414

15+
import django
1516
import pytest
1617
from django.core.exceptions import ImproperlyConfigured
1718
from django.core.serializers.json import DjangoJSONEncoder
@@ -452,11 +453,14 @@ class Meta:
452453
model = ArrayFieldModel
453454
fields = ['array_field', 'array_field_with_blank']
454455

456+
validators = ""
457+
if django.VERSION < (4, 1):
458+
validators = ", validators=[<django.core.validators.MaxLengthValidator object>]"
455459
expected = dedent("""
456460
TestSerializer():
457-
array_field = ListField(allow_empty=False, child=CharField(label='Array field', validators=[<django.core.validators.MaxLengthValidator object>]))
458-
array_field_with_blank = ListField(child=CharField(label='Array field with blank', validators=[<django.core.validators.MaxLengthValidator object>]), required=False)
459-
""")
461+
array_field = ListField(allow_empty=False, child=CharField(label='Array field'%s))
462+
array_field_with_blank = ListField(child=CharField(label='Array field with blank'%s), required=False)
463+
""" % (validators, validators))
460464
self.assertEqual(repr(TestSerializer()), expected)
461465

462466
@pytest.mark.skipif(hasattr(models, 'JSONField'), reason='has models.JSONField')

tox.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ envlist =
33
{py36,py37,py38,py39}-django22,
44
{py36,py37,py38,py39}-django31,
55
{py36,py37,py38,py39,py310}-django32,
6-
{py38,py39,py310}-{django40,djangomain},
6+
{py38,py39,py310}-{django40,django41,djangomain},
77
base,dist,docs,
88

99
[travis:env]
@@ -12,6 +12,7 @@ DJANGO =
1212
3.1: django31
1313
3.2: django32
1414
4.0: django40
15+
4.1: django41
1516
main: djangomain
1617

1718
[testenv]
@@ -24,7 +25,8 @@ deps =
2425
django22: Django>=2.2,<3.0
2526
django31: Django>=3.1,<3.2
2627
django32: Django>=3.2,<4.0
27-
django40: Django>=4.0,<5.0
28+
django40: Django>=4.0,<4.1
29+
django41: Django>=4.1a1,<4.2
2830
djangomain: https://github.com/django/django/archive/main.tar.gz
2931
-rrequirements/requirements-testing.txt
3032
-rrequirements/requirements-optionals.txt

0 commit comments

Comments
 (0)