#37307: Short-circuit evaluation issue
------------------------------+-----------------------------------------
Reporter: Twain Byrnes | Type: Bug
Status: new | Component: Uncategorized
Version: 6.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+-----------------------------------------
Hello,
There are several instances of a potentially problematic behavior in the
Python code of the form:
{{{#!div style="font-size: 80%"
Code highlighting:
{{{#!python
def fun_name(par=None):
par = par or default_value
...
}}}
}}}
which may be passed a non-None value of the wrong type, potentially
causing errors. I have not found any instances where there it is possible
for something to be passed in with the wrong type, but for future-
proofing, it may be advisable to change them to the following form:
{{{#!div style="font-size: 80%"
Code highlighting:
{{{#!python
def fun_name(par=None):
if par is None:
par = default_value
...
}}}
}}}
I have listed several such instances below:
1. In `django/db/models/fields/__init__.py`, lines 1101 and 1115
2. In `django/db/models/base.py`, lines 705 and 706, lines 853 and 867,
lines 962 and 974, lines 1333 and 1339
If there is interest, I can also submit a CodeQL query to uncover the
remaining items of this form.
--
Ticket URL: <
https://code.djangoproject.com/ticket/37307>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.