Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: getting a group's transit agency #2309

Merged
merged 2 commits into from
Aug 19, 2024

Conversation

angela-tran
Copy link
Member

Follow-up to #2307

If we use group.transitagency to get a Group's TransitAgency, Django will raise a RelatedObjectDoesNotExist error if the group does not have a TransitAgency.

The Django docs recommend either catching the exception or checking for the attribute. This PR checks if the group has the attribute before trying to get the object.

https://docs.djangoproject.com/en/5.1/topics/db/examples/one_to_one/

image

@github-actions github-actions bot added the tests Related to automated testing (unit, UI, integration, etc.) label Aug 19, 2024
@angela-tran angela-tran self-assigned this Aug 19, 2024
@angela-tran angela-tran marked this pull request as ready for review August 19, 2024 17:11
@angela-tran angela-tran requested a review from a team as a code owner August 19, 2024 17:11
Copy link

github-actions bot commented Aug 19, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits/core
  models.py
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@angela-tran angela-tran merged commit 1aabe8a into main Aug 19, 2024
15 checks passed
@angela-tran angela-tran deleted the fix/related-object-does-not-exist branch August 19, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Related to automated testing (unit, UI, integration, etc.)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants