Skip to content

Commit fb7f482

Browse files
authored
Merge branch 'main' into fix/related-field-unhashable-get-choices
2 parents b537c68 + cf582fb commit fb7f482

7 files changed

Lines changed: 55 additions & 44 deletions

File tree

.github/workflows/main.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
pre-commit:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v6.0.2
17+
- uses: actions/checkout@v6.0.3
1818
with:
1919
fetch-depth: 0
2020

@@ -56,7 +56,7 @@ jobs:
5656
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
5757

5858
steps:
59-
- uses: actions/checkout@v6.0.2
59+
- uses: actions/checkout@v6.0.3
6060

6161
- uses: actions/setup-python@v6
6262
with:
@@ -70,9 +70,6 @@ jobs:
7070
- name: Install dependencies
7171
run: python -m pip install --upgrade tox
7272

73-
- name: Create unaccent extension
74-
run: PGPASSWORD=postgres psql -h localhost -U postgres -d postgres -c 'CREATE EXTENSION IF NOT EXISTS unaccent;'
75-
7673
- name: Run tox targets for ${{ matrix.python-version }}
7774
run: tox run -f py$(echo ${{ matrix.python-version }} | tr -d . | cut -f 1 -d '-')
7875

@@ -82,15 +79,15 @@ jobs:
8279
tox -e base,dist,docs
8380
8481
- name: Upload coverage
85-
uses: codecov/codecov-action@v6
82+
uses: codecov/codecov-action@v6.0.1
8683
with:
8784
env_vars: TOXENV,DJANGO
8885

8986
test-docs:
9087
name: Test documentation links
9188
runs-on: ubuntu-24.04
9289
steps:
93-
- uses: actions/checkout@v6.0.2
90+
- uses: actions/checkout@v6.0.3
9491

9592
- uses: actions/setup-python@v6
9693
with:

.github/workflows/mkdocs-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
concurrency:
2121
group: ${{ github.workflow }}-${{ github.ref }}
2222
steps:
23-
- uses: actions/checkout@v6.0.2
23+
- uses: actions/checkout@v6.0.3
2424
- run: git fetch --no-tags --prune --depth=1 origin gh-pages
2525
- uses: actions/setup-python@v6
2626
with:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
if: github.repository == 'encode/django-rest-framework'
2727
runs-on: ubuntu-24.04
2828
steps:
29-
- uses: actions/checkout@v6.0.2
29+
- uses: actions/checkout@v6.0.3
3030
- name: Set up Python
3131
uses: actions/setup-python@v6
3232
with:

rest_framework/fields.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -708,12 +708,13 @@ def to_internal_value(self, data):
708708
self.fail("invalid", input=data)
709709

710710
def to_representation(self, value):
711-
if self._lower_if_str(value) in self.TRUE_VALUES:
712-
return True
713-
elif self._lower_if_str(value) in self.FALSE_VALUES:
714-
return False
715-
if self._lower_if_str(value) in self.NULL_VALUES and self.allow_null:
716-
return None
711+
with contextlib.suppress(TypeError):
712+
if self._lower_if_str(value) in self.TRUE_VALUES:
713+
return True
714+
elif self._lower_if_str(value) in self.FALSE_VALUES:
715+
return False
716+
if self._lower_if_str(value) in self.NULL_VALUES and self.allow_null:
717+
return None
717718
return bool(value)
718719

719720

rest_framework/schemas/openapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ def map_field(self, field):
508508
return {'type': FIELD_CLASS_SCHEMA_TYPE.get(field.__class__, 'string')}
509509

510510
def _map_min_max(self, field, content):
511-
if field.max_value:
511+
if field.max_value is not None:
512512
content['maximum'] = field.max_value
513-
if field.min_value:
513+
if field.min_value is not None:
514514
content['minimum'] = field.min_value
515515

516516
def map_serializer(self, serializer):

tests/schemas/test_openapi.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ def test_list_field_mapping(self):
6161
(serializers.ListField(), {'items': {}, 'type': 'array'}),
6262
(serializers.ListField(child=serializers.BooleanField()), {'items': {'type': 'boolean'}, 'type': 'array'}),
6363
(serializers.ListField(child=serializers.FloatField()), {'items': {'type': 'number'}, 'type': 'array'}),
64+
(serializers.ListField(child=serializers.FloatField(min_value=0.0)),
65+
{'items': {'type': 'number', 'minimum': 0.0}, 'type': 'array'}),
66+
(serializers.ListField(child=serializers.FloatField(max_value=0.0)),
67+
{'items': {'type': 'number', 'maximum': 0.0}, 'type': 'array'}),
6468
(serializers.ListField(child=serializers.CharField()), {'items': {'type': 'string'}, 'type': 'array'}),
69+
(serializers.ListField(child=serializers.IntegerField(min_value=0)),
70+
{'items': {'type': 'integer', 'minimum': 0}, 'type': 'array'}),
71+
(serializers.ListField(child=serializers.IntegerField(max_value=0)),
72+
{'items': {'type': 'integer', 'maximum': 0}, 'type': 'array'}),
6573
(serializers.ListField(child=serializers.IntegerField(max_value=4294967295)),
6674
{'items': {'type': 'integer', 'maximum': 4294967295, 'format': 'int64'}, 'type': 'array'}),
6775
(serializers.ListField(child=serializers.ChoiceField(choices=[('a', 'Choice A'), ('b', 'Choice B')])),

tests/test_fields.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -774,33 +774,38 @@ class TestBooleanField(FieldValues):
774774
'foo': ['Must be a valid boolean.'],
775775
None: ['This field may not be null.']
776776
}
777-
outputs = {
778-
'True': True,
779-
'TRUE': True,
780-
'tRuE': True,
781-
't': True,
782-
'T': True,
783-
'true': True,
784-
'on': True,
785-
'ON': True,
786-
'oN': True,
787-
'False': False,
788-
'FALSE': False,
789-
'fALse': False,
790-
'f': False,
791-
'F': False,
792-
'false': False,
793-
'off': False,
794-
'OFF': False,
795-
'oFf': False,
796-
'1': True,
797-
'0': False,
798-
1: True,
799-
0: False,
800-
True: True,
801-
False: False,
802-
'other': True
803-
}
777+
outputs = [
778+
('True', True),
779+
('TRUE', True),
780+
('tRuE', True),
781+
('t', True),
782+
('T', True),
783+
('true', True),
784+
('on', True),
785+
('ON', True),
786+
('oN', True),
787+
('False', False),
788+
('FALSE', False),
789+
('fALse', False),
790+
('f', False),
791+
('F', False),
792+
('false', False),
793+
('off', False),
794+
('OFF', False),
795+
('oFf', False),
796+
('1', True),
797+
('0', False),
798+
(1, True),
799+
(0, False),
800+
(True, True),
801+
(False, False),
802+
('other', True),
803+
([], False),
804+
({}, False),
805+
(set(), False),
806+
([1], True),
807+
({'example': 'value'}, True),
808+
]
804809
field = serializers.BooleanField()
805810

806811
def test_disallow_unhashable_collection_types(self):

0 commit comments

Comments
 (0)