Skip to content

fix: prevent crashing using itemgetter#21

Merged
ngovinh2k2 merged 1 commit into
devfrom
fix/prevent-crashing-using-itemgetter
May 19, 2026
Merged

fix: prevent crashing using itemgetter#21
ngovinh2k2 merged 1 commit into
devfrom
fix/prevent-crashing-using-itemgetter

Conversation

@ngovinh2k2
Copy link
Copy Markdown
Member

What?

Prevent crashing using itemgetter

Why?

From the request

How?

Testing?

  • Functional Testing
  • Security
  • Performance
  • Error Handling
  • Code Quality
  • Documentation
  • Database
  • Deployment
  • Final Review

Anything Else?

@ngovinh2k2 ngovinh2k2 merged commit 0121fd8 into dev May 19, 2026
1 check passed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the authentication service to handle user information extraction more safely by replacing itemgetter with dictionary access and providing default values for optional fields. It also includes a minor formatting cleanup in a migration file. The review feedback correctly identifies that the email field is still accessed directly, which could lead to a KeyError, and suggests implementing a more graceful error handling approach using a ValidationError.

)
given_name = user_info_dict.get("given_name", "")
family_name = user_info_dict.get("family_name", "")
email = user_info_dict["email"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While the removal of itemgetter prevents crashes when given_name or family_name are missing, accessing user_info_dict["email"] directly will still raise a KeyError if the "email" key is absent. Since the email is essential for user identification and the primary goal of this PR is to prevent crashes, it is better to handle its absence gracefully by raising a ValidationError.

    email = user_info_dict.get("email")
    if not email:
        raise ValidationError({"error": "Email not provided by the authentication provider."})

@ngovinh2k2 ngovinh2k2 deleted the fix/prevent-crashing-using-itemgetter branch May 22, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant