Skip to content

Commit e36cae4

Browse files
author
nxexox
committed
rename field
1 parent 20f0332 commit e36cae4

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

docs/api-guid/fields.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class ClassNameField(serializers.Field):
333333
### Raising validation errors
334334

335335
Our `ColorField` class above currently does not perform any data validation.
336-
To indicate invalid data, we should raise a `serializers.ValidationError` or call `self.fail(detail, status=400)`, like so:
336+
To indicate invalid data, we should raise a `serializers.ValidationError` or call `self.fail_validate(detail, status=400)`, like so:
337337
```python
338338
def to_internal_value(self, data):
339339
if not isinstance(data, six.text_type):
@@ -347,7 +347,7 @@ def to_internal_value(self, data):
347347
red, green, blue = [int(col) for col in data.split(',')]
348348

349349
if any([col > 255 or col < 0 for col in (red, green, blue)]):
350-
self.fail(detail='Value out of range. Must be between 0 and 255.')
350+
self.fail_validate(detail='Value out of range. Must be between 0 and 255.')
351351

352352
return Color(red, green, blue)
353353
```

docs/release-notes.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Medium version numbers (0.x.0) may include API changes, in line with the [deprec
99
Major version numbers (x.0.0) are reserved for substantial project milestones.
1010

1111

12+
### 0.3.12
13+
14+
**Date:** [21th January 2020]
15+
16+
* Rename `fail` -> `fail_validate` in fields.
17+
1218
### 0.3.11
1319

1420
**Date:** [21th January 2020]

rest_framework/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
__/ |
99
|___/
1010
"""
11-
VERSION = (0, 3, 11)
11+
VERSION = (0, 3, 12)
1212

1313
__title__ = 'Python-Rest-Framework'
1414
__author__ = 'Deys Timofey'

rest_framework/serializers/fields.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def get_validators(self):
158158
"""
159159
return self.default_validators[:]
160160

161-
def fail(self, detail=None, status=400):
161+
def fail_validate(self, detail=None, status=400):
162162
"""
163163
We throw a normal error if custom validation error.
164164

tests/test_fields.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,15 @@ def test_fail_field_validation(self):
279279
'test-test', e.detail
280280
)
281281

282-
def test_fail(self):
282+
def test_fail_validate(self):
283283
"""
284284
Testing fail method.
285285
286286
"""
287287
field = self.field_class(**self.create_params())
288288
detail = {'error': 'test'}
289289
try:
290-
field.fail(detail=detail)
290+
field.fail_validate(detail=detail)
291291
self.fail('`.fail()` must throw as exception `ValidationError`.')
292292
except ValidationError as e:
293293
self.assertEqual(
@@ -301,7 +301,7 @@ def test_fail(self):
301301
)
302302
status = 404
303303
try:
304-
field.fail(detail=detail, status=status)
304+
field.fail_validate(detail=detail, status=status)
305305
self.fail('`.fail()` must throw as exception `ValidationError`.')
306306
except ValidationError as e:
307307
self.assertEqual(

0 commit comments

Comments
 (0)