From 20ce4c2363e47275bbebd557b7ccb76dd3d53b13 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Fri, 3 May 2024 15:03:56 +0000 Subject: [PATCH] fix(models): allow SecretNameField to be blank since it is not a required field on many models overriding blank=False made it so a model could not be saved in the Admin without providing a value --- benefits/core/models.py | 2 -- tests/pytest/core/test_models.py | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/benefits/core/models.py b/benefits/core/models.py index 959c94451..d04ff9a12 100644 --- a/benefits/core/models.py +++ b/benefits/core/models.py @@ -37,8 +37,6 @@ def __init__(self, *args, **kwargs): # although the validator also checks for a max length of 127 # this setting enforces the length at the database column level as well kwargs["max_length"] = 127 - # similar to max_length, enforce at the field (form) validation level to not allow blanks - kwargs["blank"] = False # the default is False, but this is more explicit kwargs["allow_unicode"] = False super().__init__(*args, **kwargs) diff --git a/tests/pytest/core/test_models.py b/tests/pytest/core/test_models.py index 1cb359fc4..3ed267e93 100644 --- a/tests/pytest/core/test_models.py +++ b/tests/pytest/core/test_models.py @@ -25,6 +25,13 @@ def test_SecretNameField_init(): assert field.description != "" +def test_SecretNameField_init_null_blank(): + field = SecretNameField(blank=True, null=True) + + assert field.blank is True + assert field.null is True + + @pytest.mark.django_db def test_PemData_str(model_PemData): assert str(model_PemData) == model_PemData.label