#27026 closed Bug (fixed)
Objects not fully configured after bulk_create.
Reported by: | Sjoerd Job Postmus | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.10 |
Severity: | Release blocker | Keywords: | bulk_create, postgresql, ManyToManyField |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Objects not fully configured after bulk_create.
When running bulk_create
on multiple objects, the primary key now gets set (if using postgresql), but the _state
field does not get updated.
This makes some features of the ORM work with the newly "id"-ed objects, but others not.
In particular, the following case fails:
#models.py class Country(models.Model): name = models.CharField(max_length=255) iso_two_letter = models.CharField(max_length=2) class Union(models.Model): name = models.CharField(max_length=255) countries = models.ManyToManyField(Country) #tests.py @skipUnlessDBFeature('can_return_ids_from_bulk_insert') def test_set_pk_and_allow_creating_related(self): union_eu = Union.objects.create(name='EU') country_nl = Country(name='Netherlands', iso_two_letter='NL') with self.assertNumQueries(1): Country.objects.bulk_create([country_nl]) union_eu.countries.add(country_nl)
Change History (5)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
Accepting as a 1.10 release blocker since it's a bug in a newly released feature.
comment:3 by , 8 years ago
This is the exception that occurred.
ValueError: Cannot add "<Country: Country object>": instance is on database "default", value is on database "None"
Note:
See TracTickets
for help on using tickets.
A pull request is available at https://github.com/django/django/pull/7033.