dispatch icon indicating copy to clipboard operation
dispatch copied to clipboard

Dispatch deliberately allows multiple entries for "null" fields

Open keeganland opened this issue 2 years ago • 0 comments

Here is an example in class Subsection:

description = TextField(null=True, blank=True)

Now, say a customized React form exists for this field and some backend programmer wants to check if it's empty by checking if it's not equal to the empty string. Depending how the form was programmed, certain boolean checks may pass and others fail in an unpredictable way, because when the field is unfilled it may more may not be stringlike.

I've had unexpected exceptions when writing code to get data from Dispatch because of this.

Django convention is to never allow null=True on a TextField or CharField unless circumstances demand it. Rather, blank=True, but with default='', is preferred. This guarantees when the SQL table is supposed to store data that should be interpreted as a string by Python, we don't end up needing to do checks that guarantee our object is sufficiently string-like to do the operations we need; its type is string, not "string or null".

keeganland avatar Jul 06 '21 01:07 keeganland