mirror of
https://github.com/django/django.git
synced 2024-12-27 11:35:53 +00:00
[5.0.x] Reverted "Refs #30446, Refs #34944 -- Fixed crash when adding GeneratedField with string Value()."
This reverts commit8b1acc0440
. Backport ofde4884b114
from main
This commit is contained in:
parent
7a21ea5464
commit
5b1d0a6be0
@ -1081,7 +1081,7 @@ class Value(SQLiteNumericMixin, Expression):
|
|||||||
|
|
||||||
def _resolve_output_field(self):
|
def _resolve_output_field(self):
|
||||||
if isinstance(self.value, str):
|
if isinstance(self.value, str):
|
||||||
return fields.CharField(max_length=len(self.value))
|
return fields.CharField()
|
||||||
if isinstance(self.value, bool):
|
if isinstance(self.value, bool):
|
||||||
return fields.BooleanField()
|
return fields.BooleanField()
|
||||||
if isinstance(self.value, int):
|
if isinstance(self.value, int):
|
||||||
|
@ -2227,7 +2227,6 @@ class ValueTests(TestCase):
|
|||||||
with self.subTest(type=type(value)):
|
with self.subTest(type=type(value)):
|
||||||
expr = Value(value)
|
expr = Value(value)
|
||||||
self.assertIsInstance(expr.output_field, output_field_type)
|
self.assertIsInstance(expr.output_field, output_field_type)
|
||||||
self.assertEqual(Value("foo").output_field.max_length, 3)
|
|
||||||
|
|
||||||
def test_resolve_output_field_failure(self):
|
def test_resolve_output_field_failure(self):
|
||||||
msg = "Cannot resolve expression type, unknown output_field"
|
msg = "Cannot resolve expression type, unknown output_field"
|
||||||
|
@ -848,23 +848,6 @@ class SchemaTests(TransactionTestCase):
|
|||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@isolate_apps("schema")
|
|
||||||
@skipUnlessDBFeature("supports_stored_generated_columns")
|
|
||||||
def test_add_generated_field_with_string_value(self):
|
|
||||||
class GeneratedFieldStringValueModel(Model):
|
|
||||||
value = GeneratedField(expression=Value("static string"), db_persist=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
app_label = "schema"
|
|
||||||
|
|
||||||
with CaptureQueriesContext(connection) as ctx:
|
|
||||||
with connection.schema_editor() as editor:
|
|
||||||
editor.create_model(GeneratedFieldStringValueModel)
|
|
||||||
self.assertIs(
|
|
||||||
any("None" in query["sql"] for query in ctx.captured_queries),
|
|
||||||
False,
|
|
||||||
)
|
|
||||||
|
|
||||||
@isolate_apps("schema")
|
@isolate_apps("schema")
|
||||||
@skipUnlessDBFeature("supports_stored_generated_columns")
|
@skipUnlessDBFeature("supports_stored_generated_columns")
|
||||||
def test_add_generated_field_with_output_field(self):
|
def test_add_generated_field_with_output_field(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user