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
(2.0) FilterView always returning empty QuerySet for unbound FilterSet. #930
Comments
Try using an actual |
So when I tried the following:
This is how the filters are rendered on Even though the filter was rendered with the right values, the filter had no effect as I can still see accounts that are suspended or abandoned. Moreover, when I visit page 2 by pressing the Do you see any reason why? |
Sorry - nothing obvious comes to mind. For the first issue, I'd recommend looking at the resulting SQL query. Make sure the |
I inserted a few print statements and I found the following:
So it seems that |
Hm. The django-filter/django_filters/views.py Lines 39 to 46 in b1f1c65
Is |
This isn't addressable as is. Closing pending enough info to identify an issue. |
Same problem here after upgrade to 2.0. Either default page or empty filter should be present in the URL to get the results. Is this at least documented somewhere? |
Still need more info to be able to reproduce... |
|
What info is needed exactly? Upgrading to 2.0 leads to the described behavior. Downgrading to 1.1.0 gets everything back to normal. I tried simplifying the view and the filterset to as minimalistic as possible, the behavior persists, so it seems like this should be fairly easy to reproduce. |
@moorchegue, a minimal example test case or test project that demonstrates the issue would be helpful. |
It also looks like the issue is with whatever is providing your pagination logic. Yes, there may be some incompatibility with the new version, but debugging issues in other packages is out of scope. You need to demonstrate a bug in Django Filter for there to be anything we can do here. |
OK, so the problem here is with the django-filter/django_filters/filterset.py Lines 202 to 206 in 1dde11c
This automatically returns In the view we're then setting django-filter/django_filters/views.py Lines 80 to 83 in 1dde11c
Hence the observed behaviour. The test for this isn't failing because the test template is using django-filter/tests/templates/tests/book_filter.html Lines 3 to 5 in 1dde11c
The immediate work around is to set We'll have a think and improve the handling for the unbound case. |
Hm. The primary deficiency here is the disparity between the View's Additionally, there is no strict/non-strict handling for the DRF backend. |
I'll WIP this up. |
@rpkilby Is there any progress on this issue? |
Yep - started the PR but had to put my open source work on hold. I should be able to pick up where I left off fairly soon. |
Note that the workaround should be to set |
Can't you just change the condition to return the qs in case of unbounded form? e.g.
Thanks. |
I have the a view,
AccountList
, which is trying to render a django_table2 table. The view's source code:This view is currently using this filterset (from django_filters):
Using this template:
This is my from my urls.py
When I visit my page,
127.0.0.1:8000
, I see that the filters are not set:But then if i do
127.0.0.1:8000?page=1
, I see the filters are initialized properly:What is causing my filters to not have default value when I don't have page=1 appended to my url?
The text was updated successfully, but these errors were encountered: