#25363: Model fields pre_save not called if force_insert=True ----------------------------------------------+--------------------------- Reporter: davidfischer-ch | Owner: nobody Type: Bug | Status: new Component: Database layer (models, ORM) | Version: 1.8 Severity: Normal | Keywords: pre_save,save Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ----------------------------------------------+--------------------------- Hello,
We use UUIDs as primary keys. Because a collision is unlikely to happen, we set the default value of the model's PK field to uuid.uuid4. But then, we had some issues with Django trying to UPDATE and then INSERT (OK we can understand the logic, but its boring). So we created a small mixin that set the value of force_insert to self._state.adding. Unfortunately we discovered that the pre_save method of the fields aren't called if insert is forced: https://github.com/django/django/blob/master/django/db/models/base.py#L786. That's an undocumented and unexpected feature. The documentation specify that the Field's pre_save methods are called on save, and its a save. Expected: Field.pre_save called unconditionally. Current: Field.pre_save called at some conditions. Workaround: Connect to model pre_save signal ... -- Ticket URL: <https://code.djangoproject.com/ticket/25363> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/058.91b7b70300f3f3744215c2b61c0da64f%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.