question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No request passed to custom filter as self.request

See original GitHub issue

Hi,

I could be doing something wrong or else this is a bug.

When creating a custom filter and I override the queryset as per the Filtering docs:

   @property
    def qs(self):
        # The query context can be found in self.request.
        print(self.request.user)
        return super(CustomFilter, self)

self.request is always None

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
danpalmercommented, May 30, 2018

Hey @syrusakbary any chance this could be released? It feels like a pretty major blocker (certainly is for our use case of filtering a list for a logged in user), and installing from master breaks a lot of Python packaging workflows, not to mention means that other unreleased and possibly untested code might be used in production.

1reaction
codekilncommented, Feb 20, 2018

In my case, I was using DjangoFilterConnectionField, and I could see that it’s connection_resolver method wasn’t supplying the request parameter. If you look at the master branch, you can see that the request object was just added as a parameter in 1db1cbdd9. I don’t know why, but the latest version in PyPI is 2.0.0, which doesn’t include that commit. It seems as though we’re due for a release, but I can’t find any tickets saying when.

Read more comments on GitHub >

github_iconTop Results From Across the Web

django-filter custom filter not get queryset - Stack Overflow
To fix this, you need to pass the user_id (of the worker you wish to check) to this queryset somehow. Maybe using the...
Read more >
No field filters form on the browsable API #64 - GitHub
I have a rest_framework_filters.FilterSet-derived class which works perfectly for filtering but it doesn't show any field filters in the ...
Read more >
Filtering - Django REST framework
Overriding this method allows you to customize the queryset returned by the view ... user = self.request.user return Purchase.objects.filter(purchaser=user) ...
Read more >
ModelAdmin List Filters - Django documentation
For custom filtering, you can define your own list filter by subclassing ... 'decade' def lookups(self, request, model_admin): """ Returns a list of...
Read more >
Django Admin list_filter | Blog - DoTheDev
Fields that exist in the database; Default Date Filter; Custom Filter ... def queryset(self, request, queryset): if not self.value(): return ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found