django-url-filter icon indicating copy to clipboard operation
django-url-filter copied to clipboard

Filters against decimals are removed if the query decimal is too long

Open jonathan-golorry opened this issue 7 years ago • 3 comments

It seems that if the decimal in the url is not within the specifications given in the model definition, then the filter fails and returns everything.

class Test(models.Model):
    my_number = models.DecimalField(max_digits=2, decimal_places=1)

Test.objects.create(my_number=1.5)

1 result: /test/ /test/?my_number__gte=1 /test/?my_number__gte=1.0 /test/?my_number__gte=.0 /test/?my_number__gte=2.00 <- incorrect /test/?my_number__gte=20 <- incorrect

0 results: /test/?my_number__gte=2 /test/?my_number__gte=2.0

jonathan-golorry avatar Jan 26 '18 02:01 jonathan-golorry

That's expected. You can change the strictness mode on the filterset to raise errors vs default behavior of dropping the filter criteria.

miki725 avatar Jan 26 '18 02:01 miki725

No option for the filter to work normally? These filters work perfectly fine in the django ORM.

jonathan-golorry avatar Jan 26 '18 03:01 jonathan-golorry

you can always overwrite the filterset filter/field to be less strict. making less strong validations seems like could be dangerous

miki725 avatar Jan 26 '18 04:01 miki725