Fix for account screen server error#1169
Merged
xzzy merged 1 commit intodbca-wa:masterfrom Feb 12, 2026
Merged
Conversation
| if person_id is None: | ||
| if "email" in self.initial: | ||
| print (self.initial['email']) | ||
| person_id = EmailUser.objects.get(email=self.initial['email']) |
There was a problem hiding this comment.
Bug: The user lookup by email assigns the full EmailUser object to person_id instead of its ID, causing a ValueError on a later type conversion. It also lacks a try...except block, risking an unhandled DoesNotExist exception.
Severity: HIGH
Suggested Fix
Modify the query to retrieve the user's ID directly by appending .id or .pk. Additionally, wrap the EmailUser.objects.get() call in a try...except EmailUser.DoesNotExist block to gracefully handle cases where the email does not exist in the database.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: ledger/accounts/forms.py#L215
Potential issue: When the form is initialized with an email but no ID, the code at
`ledger/accounts/forms.py:215` looks up the user. This lookup has two failure modes.
First, if a user is found, the entire `EmailUser` object is assigned to `person_id`, not
its integer ID. This object is later stringified (e.g., to 'user@example.com') and
stored in a hidden form field. When the form is submitted, an attempt to convert this
string back to an integer via `int()` will raise a `ValueError`. Second, if no user is
found for the provided email, the `EmailUser.objects.get()` call will raise an unhandled
`EmailUser.DoesNotExist` exception, causing a server error.
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.