Tomasz Rydzyński
aa4421c84c
Add error codes to ValidationError
...
This change addresses use cases that require more information about reported
validation errors. Currently for each error that REST Framework reports users
get only that error's message string. The message can be translated so there's
no good way to recognize programmatically what sort of an error it is.
When building an API that is supposed to return error codes, I've found it very
limiting. For example, I was supposed to differentiate between missing fields
and invalid arguments. The only way to do it right now was to monkey-patch all
hard coded error messages and prefix them with an error code, then write a custom
exception handler that unpacked those error codes and acted accordingly.
Alternatively, I could write my own set of Field and Validator classes that
would throw different exception. In either case, it felt like this is something
that has to be addressed within the REST Framework itself.
This commit introduces proper error codes handling to the Validation Error, and
a customizable error builder that let's users pick how they want to represent
their errors.
ValidationError can hold a single error itself (text), a list of those, or a
dictionary mapping errors to fields. Error code is only meaningful for a single
error, and I've added assertions to check for proper usage.
To help with my development, I've added a setting that makes error code a
mandatory argument. Thanks to this, I was able to correct all uses of
ValidationError across the code.
Information about errors was originally available via ValidationError.detail,
and format of these data must not change, because users can have custom
exception handlers that rely on it. So to maintain backward compatibility, I've
added customizable error builder. By default, it discards the error code.
Users are supposed to change that error builder in settings if they want to use
error codes in their exception handler. If they do so, the structure of
ValidationError.detail does not change, but in the leafs they'll find results
from their error builder.
2015-07-10 16:57:40 +02:00
Xavier Ordoquy
061081c732
Merge pull request #3133 from YuriHeupa/patch-2
...
Changed typo in Renderer docs of BrowsableAPIRenderer
2015-07-10 08:15:35 +02:00
Yuri Hernani Heupa
c04c8808c6
Changed typo in Renderer docs
...
The BrowsableAPIRenderer was misspelled with an extra 'e' letter
2015-07-09 22:41:53 -03:00
Xavier Ordoquy
f33ca01511
Merge pull request #3112 from juannyG/master
...
Fix nested serializer required=False multipart data validation bug
2015-07-08 15:15:14 +02:00
Juan Gutierrez
2887fc4a0b
update QueryDict initialization to satisfy older versions of Django
2015-07-08 08:25:12 -04:00
Juan Gutierrez
35db2b142f
remove FakeMultiDict definition in nested serializer tests and replace with django QueryDict
2015-07-08 08:19:42 -04:00
José Padilla
8e6db16e91
Merge pull request #3118 from dealertrack/master
...
Added django-rest-framework-braces in Misc list of 3rd party tools
2015-07-06 18:07:59 -04:00
Miroslav Shubernetskiy
3bb9e251d7
added django-rest-framework-braces in Misc list of 3rd party tools
2015-07-06 17:35:21 -04:00
Xavier Ordoquy
b24741ae89
Merge pull request #3114 from jpadilla/master
...
Fix custom parser example
2015-07-06 10:22:09 +02:00
José Padilla
f161241e07
Fix custom parser example
2015-07-05 16:48:33 -04:00
Juan Gutierrez
b0c5f9db2f
allow a non-required nested serializer to validate correctly when receiving multipart data
2015-07-03 12:28:48 -04:00
José Padilla
c091addb83
Merge pull request #3105 from MattBroach/broach
...
added link to Django Rest Multiple Models to Third Party Packages on Generic Views API docs
2015-07-02 18:35:45 -04:00
Matt Broach
b9e09e2f90
Added django-rest-multiple-models link to general Third Party resources page as well
2015-07-02 18:18:30 -04:00
Matt Broach
9e58bf6500
added link to Django Rest Multiple Models to Third Party Packages
2015-07-02 17:20:41 -04:00
Tom Christie
c3507552d5
Merge pull request #3104 from Seraf/master
...
Adding recursion on child of List Field
2015-07-02 13:30:28 +01:00
Julien Syx
2b979d4356
Adding recursion on child of List Field
2015-07-02 14:15:43 +02:00
Tom Christie
8d69c4c068
Improve OPTIONS descriptions for lists dicts and nested serializers
2015-07-02 12:55:42 +01:00
Tom Christie
21ec3b506a
Merge pull request #3103 from tomchristie/trollknurr-master
...
Ensure no duplication of results with SearchFilter with Oracle databases.
2015-07-02 12:23:31 +01:00
Tom Christie
e6ca0fcb4c
Remove erronous newline
2015-07-02 11:53:05 +01:00
Tom Christie
37815920e3
Update to master and tweak remaining issues
2015-07-02 11:50:40 +01:00
Tom Christie
055986b5b0
More helpful exception when URL cannot reverse and field value was empty. Closes #2698 .
2015-07-02 11:36:14 +01:00
Tom Christie
c4f908d4ee
Introduce datetime_parser as class level attribute on all date/time fields. Refs #3093 .
2015-07-02 11:23:52 +01:00
Tom Christie
6ce9e3baf0
Remove datetime_parser argument from DateTimeField
2015-07-02 11:22:18 +01:00
Tom Christie
6d79ea2cde
Merge pull request #3093 from sorreltree/master
...
Ability to customize DateTimeField with a custom datetime_parser
2015-07-02 11:21:25 +01:00
Tom Christie
fb4233736f
Empty settings should also be coerced to lists. Closes #3087 .
2015-07-02 10:28:46 +01:00
Tom Christie
a03b89f326
Restrict isort to rest_framework and tests directories
2015-07-02 10:18:08 +01:00
Tom Christie
d979dc6522
Tweak exception message
2015-07-02 10:16:43 +01:00
Tom Christie
e3c3d8826f
Merge pull request #3071 from antonyc/patch-1
...
Made exception message more verbose
2015-07-02 10:14:01 +01:00
Tom Christie
39ed03c21c
Merge pull request #3088 from atleta/master
...
Handle AttributeError as well (when the imported module exists but the specified function/class does not).
2015-07-02 09:52:53 +01:00
Tom Christie
5fd346a8d3
Merge pull request #3102 from linovia/feature/update_django_filter
...
Upgrade django-filter to 0.10.0
2015-07-02 09:19:08 +01:00
Xavier Ordoquy
4b5f18d293
Upgrade django-filter to 0.10.0
2015-07-01 23:19:50 +02:00
Xavier Ordoquy
c5a1427c7a
Merge pull request #3100 from bitterjug/fixdocs
...
Remove unused import from docs example
2015-07-01 21:50:28 +02:00
Mark Skipper
b743818430
Remove unused import from docs example
2015-07-01 20:39:05 +01:00
Tom Christie
a63fd55067
Merge pull request #3099 from tredzko/master
...
Update extra_kwargs on model serializer for required and read_only
2015-07-01 16:30:01 +01:00
Tyler Redzko
af08c70242
Update extra_kwargs on model serializer
...
Ensures that the 'read_only' and 'required' keys from `extra_kwargs` are
retained when present. Closes #3091 .
2015-07-01 10:10:18 -04:00
José Padilla
5bb02cc7b9
Merge pull request #3094 from linovia/bug/2893
...
Update `get_serializer` signature (fix #2893 )
2015-06-30 18:53:53 -04:00
Xavier Ordoquy
b6e46a6483
Update get_serializer
signature
...
- remove the `files` and `allow_add_remove` arguments that were part of the 2.x API.
2015-07-01 00:26:54 +02:00
Michael Bacon
5f40ab53de
Ability to customize DateTimeField with a custom datetime_parser
2015-06-30 14:51:47 -04:00
José Padilla
ca455fc80f
Merge pull request #3090 from alasdairnicol/2900
...
Fixed #2900 -- Made example validator class in docs inherit from object
2015-06-30 13:03:14 -04:00
Alasdair Nicol
061cc5a42b
Fixed #2900 -- Made example validator class in docs inherit from object
2015-06-30 16:33:01 +01:00
Laszlo Marai
f0bced6413
Handle AttributeError as well (when the imported module exists but
...
the specified function/class does not).
2015-06-30 05:49:44 +02:00
Tom Christie
5833a1847f
Merge pull request #3086 from vstoykov/fix-manyrelated-choices
...
Fix ManyRelatedField.choices
2015-06-29 14:21:47 +01:00
Venelin Stoykov
c3c9a712fa
Fix ManyRelatedField.choices
...
Use choices from self.child_relation.
We don't need to repeat ourself because can get out of sync.
2015-06-29 15:35:55 +03:00
Tom Christie
36e4f20111
Update runtests.py
2015-06-29 09:39:27 +01:00
Tom Christie
af1a4bd683
Merge pull request #3085 from jpadilla/import-cleanup
...
Print helpful command if isort fails
2015-06-29 09:38:34 +01:00
José Padilla
0f1d9217f0
Print helpful command if isort fails
2015-06-27 16:06:53 -04:00
Tom Christie
3e1687282b
Merge pull request #3048 from jpadilla/import-cleanup
...
Cleanup import following PEP 8 style guide
2015-06-26 14:55:28 +01:00
José Padilla
b4ba8ef4d7
Setup isort for code style linting
2015-06-26 09:16:33 -04:00
José Padilla
7351a3f6ca
Sort imports with isort
2015-06-25 16:55:51 -04:00
José Padilla
83c9136c90
Cleanup import following PEP 8 style guide
2015-06-25 16:10:17 -04:00