Skip to content

[auth0] Fall back to email if first and last names not found - #65

Merged
rudokemper merged 2 commits into
mainfrom
rk/fallback-to-email-if-no-names-found
Aug 3, 2026
Merged

rudokemper merged 2 commits into
mainfrom
rk/fallback-to-email-if-no-names-found

Conversation

@rudokemper

@rudokemper rudokemper commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

#64 introduced a change where we pull given_name and family_name from auth0 instead of trying to construct these from a full name string using a space delimiter. But I didn't think of the case where a user created an auth0 account with username and password, hence no given_name or family_name fields were set. This resulted in two users this morning reporting being unable to login to Superset.

This PR fixes that by setting the fallback to an empty string, which I confirmed works in Superset (see my comment #65 (comment))

@IamJeffG IamJeffG left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just want to make sure you want the email address in all 3 fields? That might look ugly.

I wonder if Superset has its own logic at display time for dealing with missing first_name, last_name, i.e. should we be setting them to empty strings instead?

Comment thread docker/pythonpath/superset_config.py Outdated
Comment on lines +238 to +239
"first_name": me.get("given_name") or me["email"],
"last_name": me.get("family_name") or me["email"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FYI dict.get takes an optional 2nd argument, which is the default value when not found

Suggested change
"first_name": me.get("given_name") or me["email"],
"last_name": me.get("family_name") or me["email"],
"first_name": me.get("given_name", me["email"]),
"last_name": me.get("family_name", me["email"]),

Note that my suggested code will still resolve me["email"] no matter what (your code will not, at least not on this line). That matters because if "email" were not defined it could fail with a KeyError. (But in thsi particular file that would have already happened on line 236.)

@rudokemper
rudokemper force-pushed the rk/fallback-to-email-if-no-names-found branch from 8acf55f to ce2825f Compare August 3, 2026 16:32
@rudokemper

rudokemper commented Aug 3, 2026 •

Copy link
Copy Markdown
Member Author

Just want to make sure you want the email address in all 3 fields? That might look ugly.

I wonder if Superset has its own logic at display time for dealing with missing first_name, last_name, i.e. should we be setting them to empty strings instead?

Thanks for the thought. Previously, we actually already had this behavior of setting email address to be the names if a user signs in with username & password and therefore there is no first_name or last_name.

Flask doesn't like having these be None:

2026-08-03T16:30:25.720319815Z 2026-08-03 16:30:25,719:ERROR:flask_appbuilder.security.sqla.manager:Error adding new user to database. (psycopg2.errors.NotNullViolation) null value in column "first_name" of relation "ab_user" violates not-null constraint

But, I tried...

                "first_name": me.get("given_name") or "",
                "last_name": me.get("family_name") or "",

And this actually works for Flask, and shows as empty strings on the web app:

image

I think this is preferable over having email be the name(s) so I will adopt this approach.

@rudokemper
rudokemper force-pushed the rk/fallback-to-email-if-no-names-found branch from ce2825f to e41217f Compare August 3, 2026 16:38
@rudokemper
rudokemper requested a review from IamJeffG August 3, 2026 16:41
@rudokemper

Copy link
Copy Markdown
Member Author

PR body now updated, and the code is ready for review.

@rudokemper rudokemper self-assigned this Aug 3, 2026
Comment thread docker/pythonpath/superset_config.py Outdated
"last_name": me["family_name"],
"first_name": me.get("given_name")
or "", # Auth0 will not return first (or last) name if users signed up with email and password instead of social login
"last_name": me.get("family_name") or "",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This, tooo, can be me.get("family_name", "") but your call!

@rudokemper
rudokemper merged commit 35ede43 into main Aug 3, 2026
1 check passed
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