summaryrefslogtreecommitdiff
path: root/tests/model_fields
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-12-07 20:50:18 +0100
committerGitHub <noreply@github.com>2023-12-07 20:50:18 +0100
commit5b3b791e9046461901df3898be8544e14d91b931 (patch)
treece325771318e61cfe009023039dc147d43acb461 /tests/model_fields
parent2dca98f4f76e1296b842b183a9287086ec416b58 (diff)
Fixed #35024 -- Fixed model instance creation crash on GeneratedField.output_field with backend converters.
Regression in d9de74141e8a920940f1b91ed0a3ccb835b55729. 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.
Diffstat (limited to 'tests/model_fields')
-rw-r--r--tests/model_fields/models.py12
-rw-r--r--tests/model_fields/test_generatedfield.py8
2 files changed, 20 insertions, 0 deletions
diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py
index b4b7b5bd4c..aea02964e2 100644
--- a/tests/model_fields/models.py
+++ b/tests/model_fields/models.py
@@ -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()
diff --git a/tests/model_fields/test_generatedfield.py b/tests/model_fields/test_generatedfield.py
index 9e5d9d87c3..056a80c294 100644
--- a/tests/model_fields/test_generatedfield.py
+++ b/tests/model_fields/test_generatedfield.py
@@ -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):