-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
failing test: #4936
When using a ModelSerializer for a model with a ManyToMany field, and applying required=False to that field in extra_kwargs, omitting the ManyToManyField in the data results in a validation error ("This list may not be empty.") for form data requests (including from the browsable api form), but not for JSON requests.
On closer inspection, I found that when using the serializer directly, passing a dict, the validation error doesn't appear; whereas when passing a QueryDict it does.
Checklist
- I have verified that that issue exists against the
masterbranch of Django REST framework. - I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- This is not a usage question. (Those should be directed to the discussion group instead.)
- This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
- I have reduced the issue to the simplest possible case.
- I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
Steps to reproduce
I created a toy project to reproduce the bug.
Expected behavior
The validation shouldn't differ between form data requests and JSON requests. Because the field has the option required=False, omitting the field shouldn't prevent deserialization; thus the JSON behaviour is correct.
Actual behavior
When passing the data in a dict, omitting the many to many field ('tags' in the toy project linked above), the data passes validation; whereas passing a QueryDict (or making a request with form data rather than json) results in a validation error with message "This list may not be empty."