#36550: AssertionError raised when bulk creation model with primary key set via
pre_save (e.g. auto_now_add)
-------------------------------------+-------------------------------------
Reporter: Will-Ruddick | Owner: (none)
Type: Bug | Status: closed
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):
* resolution: => wontfix
* severity: Release blocker => Normal
* status: new => closed
* summary:
AssertionError raised when bulk creation model with composite primary
key with auto_now_add field
=>
AssertionError raised when bulk creation model with primary key set
via pre_save (e.g. auto_now_add)
Comment:
Been looking into this more today
This actually doesn't have anything to do with `CompositePrimaryKey` and
we can have the same error doing
`TimeStamped.objects.bulk_create([TimeStamped()])` when `TimeStamped` is:
{{{
class TimeStamped(models.Model):
created = models.DateTimeField(auto_now_add=True, primary_key=True)
}}}
I believe the route of this is documented
(https://docs.djangoproject.com/en/5.2/ref/models/querysets/#bulk-create):
> The model’s save() method will not be called, and the pre_save and
post_save signals will not be sent.
And the value for created is defined on the field's `pre_save` method
To support bulk_create to support primary_keys that are set of pre_save
would be a new feature. We _might_ be able to detect this better and have
a nicer error message
But in short, I do think this is roughly expected behavior with some
documentation and so will close
--
Ticket URL: <https://code.djangoproject.com/ticket/36550#comment:5>
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 [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070198a8989814-7f2b0d6b-59c0-4a8d-8bf6-d341227abdfb-000000%40eu-central-1.amazonses.com.