1
0
mirror of https://github.com/django/django.git synced 2025-04-04 13:36:42 +00:00

Fixed #36262 -- Made GeneratedField.db_persist a required key-word argument.

This commit is contained in:
Jason Cameron 2025-03-18 00:38:31 -04:00 committed by Sarah Boyce
parent 334677ad57
commit 9608678704
4 changed files with 5 additions and 4 deletions

View File

@ -479,6 +479,7 @@ answer newbie questions, and generally made Django that much better:
Jarek Głowacki <jarekwg@gmail.com>
Jarek Zgoda <jarek.zgoda@gmail.com>
Jarosław Wygoda <jaroslaw@wygoda.me>
Jason Cameron <https://jasoncameron.dev>
Jason Davies (Esaj) <https://www.jasondavies.com/>
Jason Huggins <http://www.jrandolph.com/blog/>
Jason McBrayer <http://www.carcosa.net/jason/>

View File

@ -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):

View File

@ -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``

View File

@ -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"),