﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36550	AssertionError raised when bulk creation model with primary key set via pre_save (e.g. auto_now_add) on databases with can_return_columns_from_insert	Will-Ruddick	Abhimanyu Singh Negi	"I have a model that looks something like this

{{{
class CompositeModel(models.Model):
    pk = models.CompositePrimaryKey(""other_model"", ""the_time"", ""created_at"")

    other_model = models.ForeignKey(""test.OtherModel"", on_delete=models.CASCADE)
    the_time = models.DateTimeField()
    created_at = models.DateTimeField(auto_now_add=True)

}}}


And when I try and bulk create it in the code I get the following exception.


{{{
    CompositeModel.objects.bulk_create(new_items)
  File ""django/db/models/manager.py"", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""django/db/models/query.py"", line 836, in bulk_create
    assert len(returned_columns) == len(objs_without_pk)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
}}}


Where `returned_columns` is an empty list and `objs_without_pk ` is a list of the objects I'm trying to create.

If I use `ignore_conflicts=True` then everything works fine and the objects are created properly in the DB. I think this is a bug, but it could be user error.

This is happening on version 5.2.5 with a postgres DB"	Bug	assigned	Database layer (models, ORM)	dev	Normal			Simon Charette	Accepted	0	0	0	1	0	0
