diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 07e1641dc14..8cceb7d9665 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -676,6 +676,10 @@ class Func(SQLiteNumericMixin, Expression): class Value(Expression): """Represent a wrapped value as a node within an expression.""" + # Provide a default value for `for_save` in order to allow unresolved + # instances to be compiled until a decision is taken in #25425. + for_save = False + def __init__(self, value, output_field=None): """ Arguments: diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 47a410268e9..42b8c8f34bc 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -1703,6 +1703,14 @@ class ValueTests(TestCase): with self.assertRaisesMessage(ValueError, msg): ExpressionList() + def test_compile_unresolved(self): + # This test might need to be revisited later on if #25425 is enforced. + compiler = Time.objects.all().query.get_compiler(connection=connection) + value = Value('foo') + self.assertEqual(value.as_sql(compiler, connection), ('%s', ['foo'])) + value = Value('foo', output_field=CharField()) + self.assertEqual(value.as_sql(compiler, connection), ('%s', ['foo'])) + class FieldTransformTests(TestCase):