Skip to content

Incorrect type. Expected pk value, received OrderedDict when updating a relationship #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
schtibe opened this issue Sep 29, 2015 · 11 comments
Labels
Milestone

Comments

@schtibe
Copy link
Contributor

schtibe commented Sep 29, 2015

I get this error:

{'errors': [{'detail': 'Incorrect type. Expected pk value, received '
                   'OrderedDict.',
         'source': {'pointer': '/data/attributes/title'},
         'status': '400'}]}

since commit d654c75 when I run my unit test. The data I send is

    data = {
        "data": {
            "type": "customers",
            "id":   self.lukeId,
            "relationships": {
                "title": {
                    "data": { "type": "titles", "id": "2" }
                }
            }
        }
    }

What is that change for / is my data wrong?

@jsenecal
Copy link
Member

I would say that this commit title says it all: 'Relationships parsing are now only handled by compatible fields'

In more details: another field was introduced shortly around the time of that commit (23d0af6)

ResourceRelatedField handles the JSONAPI spec completely and should replace any related fields you might want to use - Both for performance and features.

Let me know if you need more help on this.

@schtibe
Copy link
Contributor Author

schtibe commented Sep 29, 2015

Just noticed that I didn't mention that I send this data via PATCH.
I struggle to understand what 'compatible fields' means.

@jsenecal
Copy link
Member

It means that the parser now only parses resource identifier objects (spec) in relationships. - for that, you need fields that understand resource identifier objects like the above ResourceRelatedField.

@jerel
Copy link
Member

jerel commented Sep 29, 2015

Is that error only shown for this one issue? If so perhaps we could improve the error with something like "title cannot be parsed. Are you sure the serializer uses ResourceRelatedField and the payload complies with the jsonapi.org spec?"

@jsenecal
Copy link
Member

@jerel we would require to override ALL DRF related fields in that case as we cant get the serializers fields from the parser

@jsenecal
Copy link
Member

@schtibe can you try to use the ResourceRelatedField and give us an update on this issue ?

@schtibe
Copy link
Contributor Author

schtibe commented Sep 30, 2015

@jsenecal yes it seems to work, thank you!

@schtibe schtibe closed this as completed Sep 30, 2015
@schtibe
Copy link
Contributor Author

schtibe commented Sep 30, 2015

Although using ResourceRelatedField makes it mandatory, even though I added allow_null=True

@schtibe schtibe reopened this Sep 30, 2015
@jerel
Copy link
Member

jerel commented Sep 30, 2015

Does your model also have the relationship set to null=True, blank=True?

@jsenecal
Copy link
Member

Also, the setting is usually required=false on the relations field... See http://www.django-rest-framework.org/api-guide/serializers/#validation there is a note about this...

@schtibe
Copy link
Contributor Author

schtibe commented Sep 30, 2015

It was required=false. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants