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 validation too rigid for filters with suffixes #938

Open
SafaAlfulaij opened this issue May 2, 2021 · 5 comments
Open

Filter validation too rigid for filters with suffixes #938

SafaAlfulaij opened this issue May 2, 2021 · 5 comments
Labels

Comments

@SafaAlfulaij
Copy link
Contributor

SafaAlfulaij commented May 2, 2021

Here:

if (not filterset_class) or (k not in filterset_class.base_filters):

RangeFilter is used to specify a value of the two ends without specifying the other. It works by looking for "min/after" and "max/before" in the query param.

This should work:

Using DateFromToRangeFilter, defined this way:

last_updated = DateFromToRangeFilter()

and passing the filter:
filters[last_updated_after]=2016-01-01

will execute: .filter(last_updated__gte="2016-01-01")

Currently it fails as last_updated_after != last_updated (as in the quoted code: base_filters contains last_updated but not last_updated_after or last_updated_before)

@sliverc
Copy link
Member

sliverc commented May 21, 2021

I agree this is a bug and this should actually work. There are also other suffixes used like min and max which should work too. Any there could be custom suffixes as well. So I wonder instead of validating those filters on our own, whether there is a easy way to let the filter class validate the filters.

@sliverc sliverc added the bug label May 21, 2021
@sliverc sliverc changed the title Filter validation too rigid for RangeFilter Filter validation too rigid for filters with suffixes Sep 12, 2022
@eloi-martinez-qida
Copy link

Yes, it looks like it's a duplicate, sorry for opining another issue.

Are there any plans to fix it? This issue has been open for more than a year.

@sliverc
Copy link
Member

sliverc commented Sep 12, 2022

@eloi-martinez-qida
No worries. Welcome to DJA! This is an OSS project with only volunteer contributors. So people work on the issues which are most relevant to them.

Therefore, if you are affected by this issue, I encourage you to work on a PR. Happy to assist if needed.

@eloi-martinez-qida
Copy link

@sliverc What would be the best way to tackle the problem?

@sliverc
Copy link
Member

sliverc commented Sep 13, 2022

The best way would be to check whether the django filter class has a way to validate the filter names.

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