Nested serializer field required when required = False #7743
Replies: 19 comments
-
Please send usage questions to the discussion group, IRC or stack overflow. Thanks! :) |
Beta Was this translation helpful? Give feedback.
-
@tomchristie This looks like a bug, |
Beta Was this translation helpful? Give feedback.
-
Having same problem in viewset
keeps saying the fields in created_by are required. |
Beta Was this translation helpful? Give feedback.
-
Hi @tomchristie, just wondering if this will be fixed anytime soon? |
Beta Was this translation helpful? Give feedback.
-
@variable if you need to speed up the process the best way is to help us with a pull request. |
Beta Was this translation helpful? Give feedback.
-
Unclear to me if this is a duplicate of #2919. |
Beta Was this translation helpful? Give feedback.
-
Hi @variable
Could you expand on that? What's the error message, and what code is being run that causes it? |
Beta Was this translation helpful? Give feedback.
-
Probably not a duplicate. First step is to write the most minimal possible failing test case. |
Beta Was this translation helpful? Give feedback.
-
@tomchristie I am not able to reproduce in test case:
The only difference is I am posting via Ajax post, does it make any difference?
|
Beta Was this translation helpful? Give feedback.
-
@tomchristie |
Beta Was this translation helpful? Give feedback.
-
Given this "I am not able to reproduce in test case:" I'm going to assume this was a duplicate of #2919 (just closed now), and close this. More than happy to reconsider if anyone can expand on this with a failing example case. |
Beta Was this translation helpful? Give feedback.
-
I m having exactly the same problem. As mentioned by Anton,
In Address model Street is a required field. I want to have the ship_address to be optional in CustomerSerializer.
Please suggest... |
Beta Was this translation helpful? Give feedback.
-
The discussion group is the best place to take this point and other usage questions. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Looks like this issue was never fixed. Having the same problem as @Anton-Shutik and @sandeepginside and it is not a duplicate of #2919 |
Beta Was this translation helpful? Give feedback.
-
Hi @mihailb. The easiest place to start would be to turn #2719 (comment) into a failing test case/PR. |
Beta Was this translation helpful? Give feedback.
-
Why is this closed? Looks like an important bug to me and can't see any info on that elsewhere. Is there a work around? By using a custom name instead of the model field name and specifying the user_details = UserSerializer(
read_only=True,
source='user',
) instead of user = UserSerializer(
read_only=True,
) which generates a HTTP 400 field required. Note that this prevents the use of the Also, @tomchristie refers this issue in a reply in the mailing list, however no informations help to overcome the problem here. (https://groups.google.com/forum/#!topic/django-rest-framework/ttq8PUAU424) |
Beta Was this translation helpful? Give feedback.
-
Reopening, since @sandeepginside's example should be enough to create a test case. |
Beta Was this translation helpful? Give feedback.
-
Just a hint for some of you experiencing this - I found that in my case it was caused by a unique_together constrain on the model which forced the field at hand to behave as required=True. |
Beta Was this translation helpful? Give feedback.
-
May be this answer solves your problem: |
Beta Was this translation helpful? Give feedback.
-
Hi there,
I'm on DRF 3.1.0 and Django 1.7.6 and have serializers like below:
and it works fine when doing like this (usual dict):
BUT it fails when serializer created with request.data in the view, because request.data has MergeDict type
I understand that 'zip' and 'addr1' required fields on Address, but in this case Address is not required at all.
Am I doing smth wrong or any ideas how to fix that ?
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions