question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Customizing User model to add more details

See original GitHub issue

The user model in Superset only contains the following fields:

username
firstName
lastName
userId
isActive
email

If I want to add more (let’s say country, location, etc.) how would I go about it? I looked at the UserAttribute class, but not quite sure how to use it.

Would I need to customize the schema for ab_user table? And if so, how can I do that?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
BigDataArtistcommented, Dec 14, 2020

Hi, can you please share the full code? we want to add a few more fields and we cannot do them into our DB. Is it possible to share the full code?

1reaction
jay-finncommented, Apr 6, 2020

For anyone who runs into a similar issue, I resolved this by overriding the User class from flask_appbuilder.security.sqla.models.

from flask_appbuilder.security.sqla.models import User
from sqlalchemy import (
    Column,
    String
)
class CustomUser(User):
    __tablename__ = "ab_user"
    time_zone = Column(String(64))

This adds time_zone to the schema for ab_user. After this, override the add_user function from class SupersetSecurityManager. Note that if you’re implementing auth through an external OAuth provider, you’d already be doing this.

from superset.security import SupersetSecurityManager
class CustomSsoSecurityManager(SupersetSecurityManager):
  def add_user(
        self,
        username,
        first_name,
        last_name,
        email,
        role,
        password="",
        hashed_password="",
        time_zone=""
    ):
Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a Custom User Model in Django - TestDriven.io
This post explains step-by-step how to create a custom User model in Django so that an email address can be used as the...
Read more >
Django Best Practices: Custom User Model | LearnDjango.com
Implement and add extra fields to a custom user model in Django.
Read more >
How to Create a Custom Django User Model - Blog Post
1. Create a new app · 2. Create the Custom User Model in models.py · 3. Create the User model manager · 4....
Read more >
Extending the User model with custom fields in Django
If you wish to store information related to User , you can use a one-to-one relationship to a model containing the fields for...
Read more >
Customizing authentication in Django
You can give your models custom permissions that can be checked through Django's authorization system. You can extend the default User model, or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found