Skip to content

Commit

Permalink
chore(models): remove null=True from TextFields
Browse files Browse the repository at this point in the history
change default to empty string

these are stored as the empty string when blank=True
Django recommends against null=True on TextFields: https://docs.djangoproject.com/en/5.1/ref/models/fields/#null
  • Loading branch information
thekaveman committed Nov 19, 2024
1 parent 56c87d4 commit b413ddc
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 47 deletions.
78 changes: 61 additions & 17 deletions benefits/core/migrations/0032_optionalfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,61 +202,105 @@ class Migration(migrations.Migration):
old_name="selection_label_template",
new_name="selection_label_template_override",
),
migrations.AlterField(
model_name="enrollmentflow",
name="system_name",
field=models.SlugField(
help_text="Primary internal system name for this EnrollmentFlow instance, e.g. in analytics and Eligibility API requests.", # noqa: E501
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="selection_label_template_override",
field=models.TextField(
blank=True,
default=None,
default="",
help_text="Override the default template that defines the end-user UI for selecting this flow among other options.", # noqa: E501
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_start_template_override",
field=models.TextField(
blank=True,
default=None,
default="",
help_text="Override the default template for the informational page of this flow.",
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_unverified_template_override",
field=models.TextField(
blank=True,
default=None,
default="",
help_text="Override the default template that defines the page when a user fails eligibility verification for this flow.", # noqa: E501
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="enrollment_index_template_override",
field=models.TextField(
blank=True,
default=None,
default="",
help_text="Override the default template for the Eligibility Confirmation page (the index of the enrollment app)", # noqa: E501
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="enrollment_success_template_override",
field=models.TextField(
blank=True,
default=None,
default="",
help_text="Override the default template for a successful enrollment associated with the enrollment flow",
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="reenrollment_error_template",
field=models.TextField(
blank=True, default="", help_text="Template for a re-enrollment error associated with the enrollment flow"
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="help_template",
field=models.TextField(
blank=True,
default="",
help_text="Path to a Django template that defines the help text for this enrollment flow, used in building the dynamic help page for an agency", # noqa: E501
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="claims_scheme_override",
field=models.TextField(
blank=True,
default="",
help_text="The authentication scheme to use (Optional). If blank, defaults to the value in Claims providers",
verbose_name="Claims scheme",
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="system_name",
field=models.SlugField(
help_text="Primary internal system name for this EnrollmentFlow instance, e.g. in analytics and Eligibility API requests.", # noqa: E501
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_form_class",
field=models.TextField(
blank=True,
default="",
help_text="The fully qualified Python path of a form class used by this flow, e.g. benefits.eligibility.forms.FormClass", # noqa: E501
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="group_id",
field=models.TextField(
blank=True, default="", help_text="Reference to the TransitProcessor group for user enrollment"
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="label",
field=models.TextField(
blank=True, default="", help_text="A human readable label, used as the display text in Admin."
),
),
]
35 changes: 16 additions & 19 deletions benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ class EnrollmentFlow(models.Model):
claims_extra_claims = models.TextField(null=True, blank=True, help_text="A space-separated list of any additional claims")
claims_scheme_override = models.TextField(
help_text="The authentication scheme to use (Optional). If blank, defaults to the value in Claims providers",
default=None,
null=True,
default="",
blank=True,
verbose_name="Claims scheme",
)
Expand Down Expand Up @@ -443,38 +442,38 @@ class EnrollmentFlow(models.Model):
help_text="The JWS-compatible signing algorithm to use in Eligibility API requests for this flow.",
)
selection_label_template_override = models.TextField(
null=True,
blank=True,
default=None,
default="",
help_text="Override the default template that defines the end-user UI for selecting this flow among other options.",
)
eligibility_start_template_override = models.TextField(
null=True,
blank=True,
default=None,
default="",
help_text="Override the default template for the informational page of this flow.",
)
eligibility_form_class = models.TextField(
null=True,
blank=True,
default="",
help_text="The fully qualified Python path of a form class used by this flow, e.g. benefits.eligibility.forms.FormClass", # noqa: E501
)
eligibility_unverified_template_override = models.TextField(
help_text="Override the default template that defines the page when a user fails eligibility verification for this flow.", # noqa: E501
blank=True,
null=True,
default=None,
default="",
help_text="Override the default template that defines the page when a user fails eligibility verification for this flow.", # noqa: E501
)
help_template = models.TextField(
null=True,
blank=True,
default="",
help_text="Path to a Django template that defines the help text for this enrollment flow, used in building the dynamic help page for an agency", # noqa: E501
)
label = models.TextField(
null=True,
blank=True,
default="",
help_text="A human readable label, used as the display text in Admin.",
)
group_id = models.TextField(null=True, help_text="Reference to the TransitProcessor group for user enrollment")
group_id = models.TextField(
blank=True, default="", help_text="Reference to the TransitProcessor group for user enrollment"
)
supports_expiration = models.BooleanField(
default=False, help_text="Indicates if the enrollment expires or does not expire"
)
Expand All @@ -487,18 +486,16 @@ class EnrollmentFlow(models.Model):
help_text="If the enrollment supports expiration, number of days preceding the expiration date during which a user can re-enroll in the eligibilty", # noqa: E501
)
enrollment_index_template_override = models.TextField(
help_text="Override the default template for the Eligibility Confirmation page (the index of the enrollment app)",
null=True,
blank=True,
default=None,
default="",
help_text="Override the default template for the Eligibility Confirmation page (the index of the enrollment app)",
)
reenrollment_error_template = models.TextField(
null=True, blank=True, help_text="Template for a re-enrollment error associated with the enrollment flow"
blank=True, default="", help_text="Template for a re-enrollment error associated with the enrollment flow"
)
enrollment_success_template_override = models.TextField(
null=True,
blank=True,
default=None,
default="",
help_text="Override the default template for a successful enrollment associated with the enrollment flow",
)
supported_enrollment_methods = MultiSelectField(
Expand Down
2 changes: 1 addition & 1 deletion benefits/enrollment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def reenrollment_error(request):
"""View handler for a re-enrollment attempt that is not yet within the re-enrollment window."""
flow = session.flow(request)

if flow.reenrollment_error_template is None:
if not flow.reenrollment_error_template:
raise Exception(f"Re-enrollment error with null template on: {flow}")

if session.logged_in(request) and flow.claims_provider.supports_sign_out:
Expand Down
20 changes: 10 additions & 10 deletions tests/pytest/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ def test_EnrollmentFlow_template_overrides_claims(model_EnrollmentFlow_with_scop
== model_EnrollmentFlow_with_scope_and_claim.enrollment_success_template_override
)

model_EnrollmentFlow_with_scope_and_claim.selection_label_template_override = None
model_EnrollmentFlow_with_scope_and_claim.eligibility_start_template_override = None
model_EnrollmentFlow_with_scope_and_claim.eligibility_unverified_template_override = None
model_EnrollmentFlow_with_scope_and_claim.enrollment_index_template_override = None
model_EnrollmentFlow_with_scope_and_claim.enrollment_success_template_override = None
model_EnrollmentFlow_with_scope_and_claim.selection_label_template_override = ""
model_EnrollmentFlow_with_scope_and_claim.eligibility_start_template_override = ""
model_EnrollmentFlow_with_scope_and_claim.eligibility_unverified_template_override = ""
model_EnrollmentFlow_with_scope_and_claim.enrollment_index_template_override = ""
model_EnrollmentFlow_with_scope_and_claim.enrollment_success_template_override = ""
model_EnrollmentFlow_with_scope_and_claim.save()

assert (
Expand All @@ -348,11 +348,11 @@ def test_EnrollmentFlow_template_overrides_claims(model_EnrollmentFlow_with_scop

@pytest.mark.django_db
def test_EnrollmentFlow_template_overrides_eligibility_api(model_EnrollmentFlow_with_eligibility_api):
model_EnrollmentFlow_with_eligibility_api.selection_label_template_override = None
model_EnrollmentFlow_with_eligibility_api.eligibility_start_template_override = None
model_EnrollmentFlow_with_eligibility_api.eligibility_unverified_template_override = None
model_EnrollmentFlow_with_eligibility_api.enrollment_index_template_override = None
model_EnrollmentFlow_with_eligibility_api.enrollment_success_template_override = None
model_EnrollmentFlow_with_eligibility_api.selection_label_template_override = ""
model_EnrollmentFlow_with_eligibility_api.eligibility_start_template_override = ""
model_EnrollmentFlow_with_eligibility_api.eligibility_unverified_template_override = ""
model_EnrollmentFlow_with_eligibility_api.enrollment_index_template_override = ""
model_EnrollmentFlow_with_eligibility_api.enrollment_success_template_override = ""
model_EnrollmentFlow_with_eligibility_api.save()

assert (
Expand Down

0 comments on commit b413ddc

Please sign in to comment.