Fixed #31071 -- Disabled insert optimization for primary keys with defaults when loading fixtures.
Model.save_base() is called directly when loading fixtures and assumes
existing rows will be updated. Branching of "raw" allows to maintain
the optimization introduced in #29260 while supporting this edge case.
Regression in 85458e94e3
.
Thanks Reupen Shah for the report.
This commit is contained in:
parent
5a68f02498
commit
5779cc938a
|
@ -849,6 +849,7 @@ class Model(metaclass=ModelBase):
|
||||||
updated = False
|
updated = False
|
||||||
# Skip an UPDATE when adding an instance and primary key has a default.
|
# Skip an UPDATE when adding an instance and primary key has a default.
|
||||||
if (
|
if (
|
||||||
|
not raw and
|
||||||
not force_insert and
|
not force_insert and
|
||||||
self._state.adding and
|
self._state.adding and
|
||||||
self._meta.pk.default and
|
self._meta.pk.default and
|
||||||
|
|
|
@ -18,3 +18,7 @@ Bugfixes
|
||||||
* Fixed a regression in Django 3.0 that caused a migration crash on PostgreSQL
|
* Fixed a regression in Django 3.0 that caused a migration crash on PostgreSQL
|
||||||
10+ when adding a foreign key and changing data in the same migration
|
10+ when adding a foreign key and changing data in the same migration
|
||||||
(:ticket:`31106`).
|
(:ticket:`31106`).
|
||||||
|
|
||||||
|
* Fixed a regression in Django 3.0 where loading fixtures crashed for models
|
||||||
|
defining a :attr:`~django.db.models.Field.default` for the primary key
|
||||||
|
(:ticket:`31071`).
|
||||||
|
|
|
@ -4,6 +4,8 @@ The following classes are for testing basic data marshalling, including
|
||||||
NULL values, where allowed.
|
NULL values, where allowed.
|
||||||
The basic idea is to have a model for each Django data type.
|
The basic idea is to have a model for each Django data type.
|
||||||
"""
|
"""
|
||||||
|
import uuid
|
||||||
|
|
||||||
from django.contrib.contenttypes.fields import (
|
from django.contrib.contenttypes.fields import (
|
||||||
GenericForeignKey, GenericRelation,
|
GenericForeignKey, GenericRelation,
|
||||||
)
|
)
|
||||||
|
@ -257,6 +259,10 @@ class UUIDData(models.Model):
|
||||||
data = models.UUIDField(primary_key=True)
|
data = models.UUIDField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
|
class UUIDDefaultData(models.Model):
|
||||||
|
data = models.UUIDField(primary_key=True, default=uuid.uuid4)
|
||||||
|
|
||||||
|
|
||||||
class FKToUUID(models.Model):
|
class FKToUUID(models.Model):
|
||||||
data = models.ForeignKey(UUIDData, models.CASCADE)
|
data = models.ForeignKey(UUIDData, models.CASCADE)
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ from .models import (
|
||||||
ModifyingSaveData, NullBooleanData, O2OData, PositiveBigIntegerData,
|
ModifyingSaveData, NullBooleanData, O2OData, PositiveBigIntegerData,
|
||||||
PositiveIntegerData, PositiveIntegerPKData, PositiveSmallIntegerData,
|
PositiveIntegerData, PositiveIntegerPKData, PositiveSmallIntegerData,
|
||||||
PositiveSmallIntegerPKData, SlugData, SlugPKData, SmallData, SmallPKData,
|
PositiveSmallIntegerPKData, SlugData, SlugPKData, SmallData, SmallPKData,
|
||||||
Tag, TextData, TimeData, UniqueAnchor, UUIDData,
|
Tag, TextData, TimeData, UniqueAnchor, UUIDData, UUIDDefaultData,
|
||||||
)
|
)
|
||||||
from .tests import register_tests
|
from .tests import register_tests
|
||||||
|
|
||||||
|
@ -351,6 +351,7 @@ The end."""),
|
||||||
# (pk_obj, 790, XMLPKData, "<foo></foo>"),
|
# (pk_obj, 790, XMLPKData, "<foo></foo>"),
|
||||||
(pk_obj, 791, UUIDData, uuid_obj),
|
(pk_obj, 791, UUIDData, uuid_obj),
|
||||||
(fk_obj, 792, FKToUUID, uuid_obj),
|
(fk_obj, 792, FKToUUID, uuid_obj),
|
||||||
|
(pk_obj, 793, UUIDDefaultData, uuid_obj),
|
||||||
|
|
||||||
(data_obj, 800, AutoNowDateTimeData, datetime.datetime(2006, 6, 16, 10, 42, 37)),
|
(data_obj, 800, AutoNowDateTimeData, datetime.datetime(2006, 6, 16, 10, 42, 37)),
|
||||||
(data_obj, 810, ModifyingSaveData, 42),
|
(data_obj, 810, ModifyingSaveData, 42),
|
||||||
|
|
Loading…
Reference in New Issue