barseghyanartur / django-elasticsearch-dsl-drf

Integrate Elasticsearch DSL with Django REST framework.
https://pypi.python.org/pypi/django-elasticsearch-dsl-drf
370 stars 118 forks source link

Add optional validators to the filtering/search OR implement silent mode #102

Open alexgmin opened 5 years ago

alexgmin commented 5 years ago

If a date filter receives a invalid value, like ?date__range=foo__bar, the end result is a RequestError like this RequestError(400, 'search_phase_execution_exception', 'failed to parse date field [foo] with format [strict_date_optional_time||epoch_millis]') Considering there are legitimate search_phase_execution_exceptions, like a field not existing, shouldn't the library have the same behavior as the default drf filters, for example, which just ignores invalid values?

I'm guessing the best solution would be to validate the date before sending it to elastic, which is what django-filters does.

I'm also not sure if this affects other types than dates.

barseghyanartur commented 5 years ago

@Alexgmin:

TL;DR - I don't see it happening.

Reasons:

barseghyanartur commented 5 years ago

P.S.

The only thing I could do, is to add optional validators to the filtering/search. Developers themselves would be then responsible for adding proper validators.

alexgmin commented 5 years ago

The only thing I could do, is to add optional validators to the filtering/search. Developers themselves would be then responsible for adding proper validators.

I don't see a downside of doing this. I would appreciate it.

Thinking about it a bit more and looking at the date datatype docs, I think this should be solved in elasticsearch-dsl instead of in this package, just like the the data type validation is done in drf or django instead of on the filter packages.

orehush commented 5 years ago

When I've sent a bad value to filter data I'll get 500 http error because of bad response from ES. @barseghyanartur What do you think about to handle Request Error 400 from ES and return an empty response? I'm new in elastic search, maybe you know some way to validate query before applying it and if it bad we may skip it?

barseghyanartur commented 5 years ago

@orehush:

At the moment, you should be ignoring errors from your frontend.

Validation or silent mode will be implemented some day.

You have 3 options: