diff --git a/superset/models/core.py b/superset/models/core.py index b8293b59d34f5..7392e8796a571 100644 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -598,7 +598,12 @@ def get_sqla_engine(self, schema=None, nullpool=False, user_name=None): params['poolclass'] = NullPool uri = self.db_engine_spec.adjust_database_uri(uri, schema) if self.impersonate_user: - uri.username = user_name if user_name else g.user.username + eff_username = uri.username + if user_name: + eff_username = user_name + elif hasattr(g, 'user') and g.user.username: + eff_username = g.user.username + uri.username = eff_username return create_engine(uri, **params) def get_reserved_words(self):