Description
Checklist
3.15.1 is causing problems in prod with a change to how null values are handled.
Currently running Django. 5.0.6, django-cors-headers 4.3.1, and gunicorn 22.0.0
As an example, I have a table that keeps track of a person, an organization, and some small tidbit of info about them, with the constraint that at least 2 fields must always be filled out and have unique information:
ContactOrganizationInformation
contact=models.ForeignKey(Contact, on_delete=models.CASCADE, blank=True, null=True)
organization=models.ForeignKey(Organization, on_delete=models.CASCADE, blank=True, null=True)
information=models.ForeignKey(Information, on_delete=models.CASCADE, blank=True, null=True)
class Meta:
constraints = [
models.UniqueConstraint(fields = ['contact', 'organization', 'information', name='UniqueThree'),
models.UniqueConstraint(fields = ['contact', 'organization', name='UniqueCO'),
models.UniqueConstraint(fields = [ 'organization', 'information', name='UniqueOI'),
models.UniqueConstraint(fields = ['contact', 'information', name='UniqueCI')
]
models.CheckConstraint(
name="NotMoreThanTwoNulls',
violation_error_message= "At least 2 fields must be filled out",
check =
models.Q(contact__isnull=False, organization__isnull=False, information__isnull=True |
models.Q(contact__isnull=False, organization__isnull=True, information__isnull=False |
models.Q(contact__isnull=True, organization__isnull=False, information__isnull=False |
models.Q(contact__isnull=False, organization__isnull=False, information__isnull=False
)
]
The idea is, of the 3 fields, at least 2 must be filled out. So in 3.14, I could send a POST request like
{
contact: "A Swell Guy",
organization: "A Great Org"
}
or
{
contact: "A Swell Guy",
information: "He's actually not a swell guy, only an OK one"
}
And just leave out one of the fields out, it'd just be null in the database - which is exactly what we want; if there's no info, just leave it null
Now in 3.15.1, this results in a 400 Bad Request, and the error message, "This field is required".
This is causing problems because now all our front end requests have to be rewritten as
{
contact: "A Swell Guy",
organization: "A Great Org",
information: ""
}
In the above case, Information would still reflected in the database as Null in the database.
Our issue is having to include a blank string in POST requests, when previously, just omitting the key-value pair was enough to cause a null value. We'd prefer not having to change every single POST format, and keep the old habit of "If a key-value is not present, it's just null", instead of having to write in an empty string