Skip to content

related_link_url_kwarg doesnt work with non pk value #358

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
ghost opened this issue Jun 21, 2017 · 0 comments
Closed

related_link_url_kwarg doesnt work with non pk value #358

ghost opened this issue Jun 21, 2017 · 0 comments

Comments

@ghost
Copy link

ghost commented Jun 21, 2017

Seems like related_link_lookup_field is not respected in SerializerMethodResourceRelatedField:

class BookSerializer(serializers.HyperlinkedModelSerializer):

    authors = relations.SerializerMethodResourceRelatedField(
        source='get_authors',
        model=Author,
        many=True,
        read_only=True,
        related_link_view_name='books-authors-list',
        related_link_url_kwarg='ext_book_id',
        related_link_lookup_field='ext_book_id',
    )

  File "/src/django-rest-framework-json-api/rest_framework_json_api/renderers.py", line 140, in extract_relationships
    field_links = field.get_links(resource_instance)
  File "/src/django-rest-framework-json-api/rest_framework_json_api/relations.py", line 125, in get_links
    related_kwargs = {self.related_link_url_kwarg: kwargs[self.related_link_lookup_field]}
KeyError: 'ext_book_id'

Looks like https://github.com/django-json-api/django-rest-framework-json-api/blob/develop/rest_framework_json_api/renderers.py#L140 get_links is missing lookup_field

kwargs: {'ext_book_id': 256} http://localhost:8000/api/books/256/authors/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants