Re: [Django] #36550: AssertionError raised when bulk creation model with primary key set via pre_save (e.g. auto_now_add) (was: AssertionError raised when bulk creation model with composite primary key with auto_now_add field)

2 views
Skip to first unread message

Django

unread,
Aug 14, 2025, 8:40:36 AM8/14/25
to django-...@googlegroups.com
#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.
Reply all
Reply to author
Forward
0 new messages