Desired behaviour when passing a non boolean to filter(*__isnull)

100 views
Skip to first unread message

André Ericson

unread,
Sep 30, 2019, 10:47:12 AM9/30/19
to Django developers (Contributions to Django itself)
Hello,

I came across the discovery (due to a bug on our code) that it's possible to pass a non-boolean to the __isnull filter. What would be the desired behavior here?
Should we raise an exception or should Django use the truthy value?

If the second case is the desired behavior I have found a bug in Django that caused some unexpected behavior. If allowing non-booleans is not desired shouldn't we check for it?

I can submit a PR for the specific bug that I found but it would be nice to know if I should.

Thanks.

Adam Johnson

unread,
Sep 30, 2019, 11:32:44 AM9/30/19
to django-d...@googlegroups.com
Hi André

I think Django should use the truthy value. Please open a ticket with your bug report and then a PR.

Thanks,

Adam

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/dcbb5060-c7a1-4363-9564-e79c0ba319e6%40googlegroups.com.


--
Adam

André Ericson

unread,
Sep 30, 2019, 11:42:04 AM9/30/19
to Django developers (Contributions to Django itself)
Super. I'll look into it!


On Monday, September 30, 2019 at 5:32:44 PM UTC+2, Adam Johnson wrote:
Hi André

I think Django should use the truthy value. Please open a ticket with your bug report and then a PR.

Thanks,

Adam

On Mon, 30 Sep 2019 at 15:37, André Ericson <de.e...@gmail.com> wrote:
Hello,

I came across the discovery (due to a bug on our code) that it's possible to pass a non-boolean to the __isnull filter. What would be the desired behavior here?
Should we raise an exception or should Django use the truthy value?

If the second case is the desired behavior I have found a bug in Django that caused some unexpected behavior. If allowing non-booleans is not desired shouldn't we check for it?

I can submit a PR for the specific bug that I found but it would be nice to know if I should.

Thanks.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-d...@googlegroups.com.


--
Adam

Alexandr Aktsipetrov

unread,
Oct 3, 2019, 7:32:48 AM10/3/19
to Django developers (Contributions to Django itself)

On Monday, September 30, 2019 at 5:47:12 PM UTC+3, André Ericson wrote:
Hello,

I came across the discovery (due to a bug on our code) that it's possible to pass a non-boolean to the __isnull filter. What would be the desired behavior here?
Should we raise an exception or should Django use the truthy value?

As an anecdote, I've also got bitten by this possibility. 
An attempt to write WHERE (field IS NULL) = boolean_field as .filter(field__isnull=F('boolean_field')) didn't go as I expected. 

André Ericson

unread,
Oct 3, 2019, 8:02:24 AM10/3/19
to django-d...@googlegroups.com
The problem I found is that a join doesn't get promoted to an outer. I already started fixing it, will make a PR soon.
Was the same problem you had?

--
You received this message because you are subscribed to a topic in the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-developers/AhY2b3rxkfA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/a0558991-09d1-4b74-9b19-05a1e07916ba%40googlegroups.com.


--
André Ericson
Reply all
Reply to author
Forward
0 new messages