According to the Pastebin dump, one user has a user_id = 0
Why would you even design an application to allow that? Even if the user was deleted (as potentially indicated by a null phone number), it's still a conflict.
Why would you even design an application to allow that? Even if the user was deleted (as potentially indicated by a null phone number), it's still a conflict.
Although I agree that this is not ideal, zero is not null.
Implicit casts -- including to booleans -- are dangerous, but if you try to write APIs to try to avoid every bad thing that might happen with naive use of implicit casting in every language that might be used to consume your API, you won't be able to do anything at all.
>>> NULL == 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'NULL' is not defined
Even None, which is as close to NULL you are going to get in Python is not 0. >>> None == 0
False >>> 'truthy' if None else 'falsy'
'falsy'
>>> 'truthy' if False else 'falsy'
'falsy'
>>> 'truthy' if 0 else 'falsy'
'falsy'Out[1]: False
Idiomatic Python may say "if not user_id:" and erroneously skip this.
Idiomatic test for `None` is:
if something is None:
# ...
It would be incorrect to use `if not something:` here.