Skip to content

Better catching of error cases in .update and .create. #2202

Closed
@brianhv

Description

@brianhv

When I do a PUT through the API browser to a view whose serializer contains a source property:

last_name = serializers.CharField(source='user.last_name')

I receive the following error:

Cannot assign "{'first_name': u'first', 'last_name': u'last'}": "ContactInfo.user" must be a "User" instance

I've created a bare-bones django project that reproduces the error. Of particular note are the serializers and the model.

Relevant excerpt of IRC conversation leading to this ticket:

<BrianHV> if you clone the repo, install the stuff in the requirements.txt (just django
          1.6 and DRF 3), set up a user, and use admin to create a ContactInfo for the
          user, you should be able to reproduce
<BrianHV> I'm testing through the API browser, btw.
<kevin-brown> Yeah, I think I know what is happening
<kevin-brown> `validated_data` is being (correctly?) generated as a nested dictionary,
              and that's being assigned to the `user` parameter directly
<kevin-brown> If you can open a ticket explaining that it works in DRF 2.4, that'd be
              helpful
<kevin-brown> In DRF 2.4, it would traverse the relation and assign the properties
              directly

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions