Nested serializer source argument fails silently: field missing #9536
              
                Unanswered
              
          
                  
                    
                      dennisvang
                    
                  
                
                  asked this question in
                Potential Issue
              
            Replies: 1 comment 1 reply
-
| 
         https://github.com/encode/django-rest-framework/blob/master/rest_framework/fields.py#L431 I had to remind myself from the source what's going on here. Looks like you'll get an error if the field is required otherwise it'll be omitted. I'd suggest this neither is nor isn't a bug, it's just fuzzy behavior.  | 
  
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This looks like a bug, but maybe there's some documentation that I missed.
Suppose I have a model serializer with a field based on a nested serializer:
Normally this works.
However, there are (afaik) two cases in which
my_fieldis completely omitted from the serialized data:sourceargument (e.g. I erroneously tried to use django lookup syntax:'foo__bar_set')fooobject, i.e. ifMyModel.fooisNoneThere is no error to warn about the missing field.
Using DRF 3.15.2 on windows 10 or linux, python 3.11.
Also see here.
Beta Was this translation helpful? Give feedback.
All reactions