carltongibson / django-filter

A generic system for filtering Django QuerySets based on user selections
https://django-filter.readthedocs.io/en/main/
Other
4.41k stars 766 forks source link

Code should honor empty lists/sets/etc and not treat it as None #1609

Open daviddavis opened 11 months ago

daviddavis commented 11 months ago

In the constants file, there is an empty constant that lumps None and other empty values together. Several places use this constant to ignore values when they are None/Empty (e.g. here).

The problem is that when you call /users?id__in= for example, you'd think that no users would be returned. The query is effectively asking for users whose ids are in [] (which is no users). I'd argue that asking for users with id__in=[] is very different than id__in=None since the latter means that no filter was supplied/no filtering is desired. To give an example using django:

In [3]: User.objects.all()
Out[3]: <QuerySet [<User: admin>]>

In [4]: User.objects.filter(pk__in=[])
Out[4]: <QuerySet []>