Skip to content

fix: user.socialaccount might be None#901

Open
ifaoji wants to merge 2 commits into
phasehq:mainfrom
ifaoji:ifaoji/fix/email-get-org-member
Open

fix: user.socialaccount might be None#901
ifaoji wants to merge 2 commits into
phasehq:mainfrom
ifaoji:ifaoji/fix/email-get-org-member

Conversation

@ifaoji
Copy link
Copy Markdown

@ifaoji ifaoji commented May 22, 2026

When self hosting phase with just simple password authentication inviting new members per email does not work, because the org member does not have a social account set.

The missing check caused the following error:

ERROR [rq.worker:1216] worker 19 140338981935880 [Job 96bc1351-5992-4e99-a5ae-b4328a96dd7c]: exception raised while executing (api.emails.send_invite_email)
 Traceback (most recent call last):
   File "/env/lib/python3.12/site-packages/rq/worker.py", line 1633, in perform_job
     return_value = job.perform()
                    ^^^^^^^^^^^^^
   File "/env/lib/python3.12/site-packages/rq/job.py", line 1331, in perform
     self._result = self._execute()
                    ^^^^^^^^^^^^^^^
   File "/env/lib/python3.12/site-packages/rq/job.py", line 1365, in _execute
     result = self.func(*self.args, **self.kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/app/api/emails.py", line 89, in send_invite_email
     invited_by_name = get_org_member_name(invite.invited_by)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/app/api/emails.py", line 20, in get_org_member_name
     member_name = social_acc.extra_data.get("name")
                   ^^^^^^^^^^^^^^^^^^^^^
 AttributeError: 'NoneType' object has no attribute 'extra_data'

Just checking whether social_acc is None in get_org_member_name should be enough of a fix without major refactoring. imho an issue for this small change was not needed.
I have searched the codebase for other places, where socialaccount_set is not being checked, but this was the only place.

When self hosting, an `org_member` might not have a `socialaccount` set.
@rohan-chaturvedi
Copy link
Copy Markdown
Member

Thanks for catching this! The None check fixes the crash, but the deeper issue is that we have the name available and aren't using it.

When users sign up with email + password, auth_password.py writes the name they provided into CustomUser.full_name:

https://github.com/phasehq/console/blob/main/backend/api/models.py#L55
https://github.com/phasehq/console/blob/main/backend/api/views/auth_password.py#L220-L221

So with the current patch, password-signup users get their email address in the invite mail ("Alice (alice@acme.com) invited you...") even though we know they're Alice. The login email flow already handles this correctly — it falls back from social extra_data["name"]user.full_name → email:

https://github.com/phasehq/console/blob/main/backend/api/views/auth_password.py#L402-L415

Could we mirror that resolution chain in get_org_member_name so invite emails behave the same way?

def get_org_member_name(org_member):
    user = org_member.user

    social_acc = user.socialaccount_set.first()
    if social_acc:
        name = (social_acc.extra_data or {}).get("name")
        if name:
            return name

    if user.full_name:
        return user.full_name

    return user.email

This keeps the SSO behaviour identical, fixes the NoneType crash, and uses the real name for password-signup users when we have it.

@ifaoji
Copy link
Copy Markdown
Author

ifaoji commented May 24, 2026

Hi, thank you for your review :)

You are right, user.full_name is set in my deployment. I have tested your function in my deployment, and it worked flawlessly.
Therefore I've pushed that now to this branch.

@rohan-chaturvedi
Copy link
Copy Markdown
Member

Hi, thank you for your review :)

You are right, user.full_name is set in my deployment. I have tested your function in my deployment, and it worked flawlessly. Therefore I've pushed that now to this branch.

Great! I'll give it a quick check myself and get this merged so we can add it to next release.

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.

2 participants