diff --git a/AUTHORS b/AUTHORS index 956a5e06f1..98e06d9acc 100644 --- a/AUTHORS +++ b/AUTHORS @@ -479,6 +479,7 @@ answer newbie questions, and generally made Django that much better: Jarek Głowacki Jarek Zgoda Jarosław Wygoda + Jason Cameron Jason Davies (Esaj) Jason Huggins Jason McBrayer diff --git a/django/db/models/fields/generated.py b/django/db/models/fields/generated.py index 5b6b188df0..f6e3445b71 100644 --- a/django/db/models/fields/generated.py +++ b/django/db/models/fields/generated.py @@ -15,7 +15,7 @@ class GeneratedField(Field): _query = None output_field = None - def __init__(self, *, expression, output_field, db_persist=None, **kwargs): + def __init__(self, *, expression, output_field, db_persist, **kwargs): if kwargs.setdefault("editable", False): raise ValueError("GeneratedField cannot be editable.") if not kwargs.setdefault("blank", True): diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index 0456c0a064..169d791c3d 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -1278,7 +1278,7 @@ when :attr:`~django.forms.Field.localize` is ``False`` or ``GeneratedField`` ------------------ -.. class:: GeneratedField(expression, output_field, db_persist=None, **kwargs) +.. class:: GeneratedField(*, expression, output_field, db_persist, **kwargs) A field that is always computed based on other fields in the model. This field is managed and updated by the database itself. Uses the ``GENERATED ALWAYS`` diff --git a/tests/model_fields/test_generatedfield.py b/tests/model_fields/test_generatedfield.py index e00a665ec8..9bc96a86bb 100644 --- a/tests/model_fields/test_generatedfield.py +++ b/tests/model_fields/test_generatedfield.py @@ -94,11 +94,11 @@ class BaseGeneratedFieldTests(SimpleTestCase): ) def test_db_persist_required(self): - msg = "GeneratedField.db_persist must be True or False." - with self.assertRaisesMessage(ValueError, msg): + with self.assertRaises(TypeError): GeneratedField( expression=Lower("name"), output_field=CharField(max_length=255) ) + msg = "GeneratedField.db_persist must be True or False." with self.assertRaisesMessage(ValueError, msg): GeneratedField( expression=Lower("name"),