we should systematically enforce model constraints on .save()
Django has a nasty
bugfeature: while we can define many constraints to the models, django does not enforce anything automatically. All validations are to be done manually, and its very easy to miss one of them.
This issue is describe in details here: https://www.xormedia.com/django-model-validation-on-save/
I think we should apply the solution recommended in the page above: we should derive all our models from a common base class that reimplements save() to enforce these checks every time an object is created or updated.
class BaseModel(models.Model): def save(self, force_insert=False, force_update=False, **kw): if not (force_insert or force_update): self.full_clean() super().save(force_insert, force_update, **kw)