mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
[5.0.x] Fixed #35024 -- Fixed model instance creation crash on GeneratedField.output_field with backend converters.
Regression ind9de74141e. This is a long standing issue, however it caused a crash of GeneratedFields for all output fields that have backend-specific converters when the RETURNING clause is not supported (MySQL and SQLite < 3.35). That's why severity was exacerbated. Backport of5b3b791e90from main
This commit is contained in:
@@ -482,6 +482,18 @@ class UUIDGrandchild(UUIDChild):
|
||||
pass
|
||||
|
||||
|
||||
class GeneratedModelFieldWithConverters(models.Model):
|
||||
field = models.UUIDField()
|
||||
field_copy = models.GeneratedField(
|
||||
expression=F("field"),
|
||||
output_field=models.UUIDField(),
|
||||
db_persist=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
required_db_features = {"supports_stored_generated_columns"}
|
||||
|
||||
|
||||
class GeneratedModel(models.Model):
|
||||
a = models.IntegerField()
|
||||
b = models.IntegerField()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import uuid
|
||||
|
||||
from django.apps import apps
|
||||
from django.db import IntegrityError, connection
|
||||
from django.db.models import (
|
||||
@@ -14,6 +16,7 @@ from django.test.utils import isolate_apps
|
||||
|
||||
from .models import (
|
||||
GeneratedModel,
|
||||
GeneratedModelFieldWithConverters,
|
||||
GeneratedModelNull,
|
||||
GeneratedModelNullVirtual,
|
||||
GeneratedModelOutputFieldDbCollation,
|
||||
@@ -266,6 +269,11 @@ class StoredGeneratedFieldTests(GeneratedFieldTestMixin, TestCase):
|
||||
output_field_db_collation_model = GeneratedModelOutputFieldDbCollation
|
||||
params_model = GeneratedModelParams
|
||||
|
||||
def test_create_field_with_db_converters(self):
|
||||
obj = GeneratedModelFieldWithConverters.objects.create(field=uuid.uuid4())
|
||||
obj = self._refresh_if_needed(obj)
|
||||
self.assertEqual(obj.field, obj.field_copy)
|
||||
|
||||
|
||||
@skipUnlessDBFeature("supports_virtual_generated_columns")
|
||||
class VirtualGeneratedFieldTests(GeneratedFieldTestMixin, TestCase):
|
||||
|
||||
Reference in New Issue
Block a user