-
Notifications
You must be signed in to change notification settings - Fork 248
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
Wrong django-filter types #317
Comments
i see your point. this has been criticized before and you are absolutely right. however you also have to notice that the |
I don't fully understand all the intricacies of this but I saw that |
inversion is the way to go. actually already started working on it. |
although still not perfect, this refactoring should be a massive improvement. @markopy please have a look and test it, thanks. |
This solves my problem of using Thanks for the quick fix! |
Hey @tfranzel, these changes broke drf-spectacular here with a custom DateTimeFilter. Traceback:
Filter:
|
@lerela yeah absolutely missed that one. 🤦 |
@lerela that should do it |
It does 👍 |
I think this issue should not been closed, I upgrade to
seen = django_filters.BooleanFilter(field_name="seen", lookup_expr="isnull") |
@elonzh not quite sure how you get there. since that change
|
🤣 I'm sure I'm using version |
then we would need a reproduction of this somehow, as i can't see how it should be possible. please try to reproduce it in a minimal way so i can tackle this. |
I just start a new Django project and reproduce the issue easily.
I also print the package version.
I replace class DummyViewSet(ModelViewSet):
queryset = Dummy.objects.all()
serializer_class = DummySerializer
- filterset_class = DummyFilterSet
+ filterset_fields = {
+ "seen": ["isnull"]
+ }
filter_backends = [DjangoFilterBackend] |
awesome. thank you. i can work with that |
turns out @elonzh. easy fix for you would be to use the other import path. i'll evaluate if and how we should fix this. |
i'll close the issue again as it was a simple fix and i'm pretty sure your case is now covered @elonzh |
django-filter
fields can have a different type from the underlying model field they operate against.drf-spectacular
incorrectly makes the schema type match the model field instead of the filter.Take the following filter for example:
last_login
is adatetime
model field but the filter field isboolean
. Currently the schema has the type forhas_logged_in
asdatetime
which is incorrect.The reason, I believe, is this part of the code:
drf-spectacular/drf_spectacular/contrib/django_filters.py
Lines 57 to 60 in 243445f
The model field type is preferred over the actual filter type.
I don't understand why the model field is even used here. Is it to get additional information? Since the filter itself has a clear type I don't think the mode field type is ever relevant.
The text was updated successfully, but these errors were encountered: