fix: Prevent Users From Being Created With Missing Group/Household #4500
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
(REQUIRED)
What this PR does / why we need it:
(REQUIRED)
Currently there are a couple of ways of creating users with invalid groups/households. This puts the app into a broken state where it won't run (because Pydantic complains about the missing group/household). This PR catches this issue at the db level so at least users/developers are aware of why (and when) this happens.
Now upon user creation, if the group or household is invalid a
ValueError
is raised:Which issue(s) this PR fixes:
(REQUIRED)
Fixes #4480
Special notes for your reviewer:
(fill-in or delete this section)
@cmintey as far as I know this mostly only impacts LDAP/OIDC user creation. If possible/reasonable it's probably worth addressing this in a more user-friendly way (unsure if it's possible to configure a group/household using the user's auth service?) but at least this will prevent bad things from happening. It also gives the user a reasonable log to work with.
Testing
(fill-in or delete this section)
Added tests to LDAP and OpenID which trigger this issue. Users are no longer created in a bad state.