Skip to content
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

filter_queryset looks only for view.lookup_field, ignoring view.lookup_url_kwarg #33

Open
mlazze opened this issue Dec 23, 2016 · 0 comments

Comments

@mlazze
Copy link

mlazze commented Dec 23, 2016

DRF GenericAPIView use lookup_url_kwarg as 'The URL keyword argument that should be used for object lookup. The URL conf should include a keyword argument corresponding to this value. If unset this defaults to using the same value as lookup_field.'

In fact, in GenericAPIView.get_object() we have

# Perform the lookup filtering.
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field

assert lookup_url_kwarg in self.kwargs, (
            'Expected view %s to be called with a URL keyword argument '
            'named "%s". Fix your URL conf, or set the `.lookup_field` '
            'attribute on the view correctly.' %
            (self.__class__.__name__, lookup_url_kwarg)
        )

The problem is that in DRYPermissionFiltersBase.filter_queryset() we only check view.lookup_field:

# Check if this is a list type request
if view.lookup_field not in view.kwargs:
....

This causes filter_queryset to filter retrieve actions if lookup_url_kwarg != lookup_field and lookup_url_kwarg in view.kwargseven if it shouldn't.

Something along the lines of

# Check if this is a list type request
lookup_field = view.lookup_url_kwarg or view.lookup_field
if lookup_field not in view.kwargs:

I believe should fix it.

Am i missing something?

@mlazze mlazze changed the title filter_queryset looks only for view.lookup_field, ignoring view.lookup_url_args filter_queryset looks only for view.lookup_field, ignoring view.lookup_url_kwarg Dec 23, 2016
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

1 participant