Skip to content

Commit

Permalink
refactor: have the model property look up the context non-defensively
Browse files Browse the repository at this point in the history
consumer is responsible for handling any error that might occur from
the key not being found.
  • Loading branch information
angela-tran committed Feb 21, 2025
1 parent f0fa30e commit 21e0f69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 1 addition & 3 deletions benefits/core/models/enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ def enrollment_success_template(self):

@property
def in_person_eligibility_context(self):
system_name = self.system_name
eligibility_index = in_person_context.eligibility_index
return eligibility_index[system_name].dict() if system_name in eligibility_index.keys() else {}
return in_person_context.eligibility_index[self.system_name].dict()

def clean(self):
template_errors = []
Expand Down
5 changes: 4 additions & 1 deletion benefits/in_person/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def __init__(self, agency: models.TransitAgency, *args, **kwargs):
self.use_custom_validity = True

def get_policy_details(self, flow: models.EnrollmentFlow):
eligibility_context = flow.in_person_eligibility_context
try:
eligibility_context = flow.in_person_eligibility_context
except KeyError:
eligibility_context = None

return eligibility_context["policy_details"] if eligibility_context else None

Expand Down

0 comments on commit 21e0f69

Please sign in to comment.