Skip to content

Commit

Permalink
[sql lab] fix impersonation + template issue (apache#3644)
Browse files Browse the repository at this point in the history
When the database impersonation flag is on, a query using a template
fails. It has to do with templating using a database connection without
a username being specified by the caller, along with the fact that the
work is taking place on a worker, outside a web request, where
referencing g.user raises this exception.
  • Loading branch information
mistercrunch authored and michellethomas committed May 23, 2018
1 parent 0b31920 commit 12c5ae5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 12c5ae5

Please sign in to comment.