Open loeeess opened 1 month ago
Hi @loeeess — thanks for the report.
So I think a FilterSet
option to do one of three things when encountering an unknown field type is the way forward here: Raise (current behaviour, should be the default), Warn (pass over, but emit a warning), Ignore (silently pass over). Folks could then set either Warn or Ignore if they hit your use-case.
Would you fancy taking that on?
Thanks for your reply, @carltongibson! Sounds like a good solution to me. And yes, I can look into it.
I just added a PR (#1675) for this issue. I realize the documentation for the FilterSet
options should be updated as well. If these changes look alright, I don't mind taking on the task of updating these docs.
@loeeess Great work thanks. I left an initial comment. Let's carry on there. 👍
Hello,
I use
django-filter
in combination with DRF and I have created a custom base view for GET requests that is used for various models, and returns a list of all object instances of the selected model. Some of these models have aJSONField
, others don't. I usedjango-filter
for each field of the models. BecauseJSONField
is not covered by django-filter by default, it causes a 500 error when I retrieve the list of model instances for a model that includes aJSONField
in the response, see the following response:I am aware of the fact that I can indeed write a custom filter (which I did, works fine). But without this custom implementation, the error prevents me from viewing the GET response in the first place.
My proposed solutions would be to either;
JSONField
when creating the filters for the model attributes. Then a user can still retrieve their requested data, the only downside being that theJSONField
attributes are not included in the filter list.JSONField
in the package, where it is possible to define which key/value pairs can be filtered on.Thank you.