Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask g.user is None #14589

Closed
3 tasks done
krsnik93 opened this issue May 12, 2021 · 10 comments
Closed
3 tasks done

Flask g.user is None #14589

krsnik93 opened this issue May 12, 2021 · 10 comments
Labels
dashboard:export Related to exporting dashboards question & help wanted Use Github discussions instead

Comments

@krsnik93
Copy link
Contributor

krsnik93 commented May 12, 2021

I ran superset export-dashboards on a fresh install of latest master. I see the same error for superset export-datasources.

Expected results

Expect command to export resources.

Actual results

There was an error when exporting the dashboards, please check the exception traceback in the log                                                                                         
Traceback (most recent call last):                                                                                                                                                        
  File "/home/fedora/superset/repo/superset/superset/cli.py", line 269, in export_dashboards                                                                                              
    for file_name, file_content in ExportDashboardsCommand(                                                                                                                               
  File "/home/fedora/superset/repo/superset/superset/commands/export.py", line 50, in run                                                                                                 
    self.validate()                                                                                                                                                                       
  File "/home/fedora/superset/repo/superset/superset/commands/export.py", line 67, in validate                                                                                            
    self._models = self.dao.find_by_ids(self.model_ids)                                                                                                                                   
  File "/home/fedora/superset/repo/superset/superset/dao/base.py", line 74, in find_by_ids                                                                                                
    query = cls.base_filter(  # pylint: disable=not-callable                                                                                                                              
  File "/home/fedora/superset/repo/superset/superset/dashboards/filters.py", line 73, in apply                                                                                            
    if is_user_admin():                                                                                                                                                                   
  File "/home/fedora/superset/repo/superset/superset/views/base.py", line 258, in is_user_admin                                                                                           
    user_roles = [role.name.lower() for role in list(get_user_roles())]                                                                                                                   
  File "/home/fedora/superset/repo/superset/superset/views/base.py", line 251, in get_user_roles                                                                                          
    if g.user.is_anonymous:                                                                                                                                                               
AttributeError: 'NoneType' object has no attribute 'is_anonymous'                                                                                                                         
2021-05-12 11:34:09,092:ERROR:superset.cli:There was an error when exporting the dashboards, please check the exception traceback in the log                                              
Traceback (most recent call last):                                                                                                                                                        
  File "/home/fedora/superset/repo/superset/superset/cli.py", line 269, in export_dashboards                                                                                              
    for file_name, file_content in ExportDashboardsCommand(
  File "/home/fedora/superset/repo/superset/superset/commands/export.py", line 50, in run
    self.validate()
  File "/home/fedora/superset/repo/superset/superset/commands/export.py", line 67, in validate
    self._models = self.dao.find_by_ids(self.model_ids)
  File "/home/fedora/superset/repo/superset/superset/dao/base.py", line 74, in find_by_ids
    query = cls.base_filter(  # pylint: disable=not-callable
  File "/home/fedora/superset/repo/superset/superset/dashboards/filters.py", line 73, in apply
    if is_user_admin():
  File "/home/fedora/superset/repo/superset/superset/views/base.py", line 258, in is_user_admin
    user_roles = [role.name.lower() for role in list(get_user_roles())]
  File "/home/fedora/superset/repo/superset/superset/views/base.py", line 251, in get_user_roles
    if g.user.is_anonymous:
AttributeError: 'NoneType' object has no attribute 'is_anonymous'

How to reproduce the bug

  1. Install Superset latest master in editable mode
  2. Run superset export-dashboards

Environment

(please complete the following information):

  • superset version: 0.999.0dev
  • python version: Python 3.8.7
  • node.js version: v14.16.0

Checklist

Make sure to follow these steps before submitting your issue - thank you!

  • I have checked the superset logs for python stacktraces and included it here as text if there are any.
  • I have reproduced the issue with at least the latest released version of superset.
  • I have checked the issue tracker for the same issue and I haven't found one similar.
@krsnik93 krsnik93 added the #bug Bug report label May 12, 2021
@zhaoyongjie
Copy link
Member

Hi @krsnik93, do you run superset init before doing this?

@krsnik93
Copy link
Contributor Author

@zhaoyongjie yes + superset db upgrade

@junlincc junlincc added question & help wanted Use Github discussions instead dashboard:export Related to exporting dashboards and removed #bug Bug report labels May 21, 2021
@junlincc
Copy link
Member

is this still happening? @krsnik93

@krsnik93
Copy link
Contributor Author

@junlincc same error, retested today, latest commit 281d637

@EBoisseauSierra
Copy link
Contributor

In the same vein (I believe), I've tried to replicate on a Fedora32 VM running Superset 1.1.0 and get:

$ /opt/superset/venv/bin/superset version
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Superset 1.1.0
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$ /opt/superset/venv/bin/superset --version
Python 3.8.7
Flask 1.1.2
Werkzeug 1.0.1

[fedora@temperature ~]$ /opt/superset/venv/bin/superset export-dashboards
logging was configured successfully
INFO:superset.utils.logging_configurator:logging was configured successfully
/opt/superset/venv/lib64/python3.8/site-packages/flask_caching/__init__.py:201: UserWarning: Flask-Caching: CACHE_TYPE is set to null, caching is effectively disabled.
  warnings.warn(
Starting export
INFO:superset.utils.dashboard_import_export:Starting export
Traceback (most recent call last):
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
    self.dialect.do_execute(
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such table: dashboards

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/superset/venv/bin/superset", line 33, in <module>
    sys.exit(load_entry_point('apache-superset==1.1.0', 'console_scripts', 'superset')())
  File "/opt/superset/venv/lib64/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/superset/venv/lib64/python3.8/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/opt/superset/venv/lib64/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/superset/venv/lib64/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/superset/venv/lib64/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/superset/venv/lib64/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/superset/venv/lib64/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/opt/superset/venv/lib64/python3.8/site-packages/flask/cli.py", line 426, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/opt/superset/venv/lib64/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/superset/venv/lib64/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/opt/superset/venv/lib64/python3.8/site-packages/flask/cli.py", line 426, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/opt/superset/venv/lib64/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/superset/venv/lib64/python3.8/site-packages/superset/cli.py", line 392, in export_dashboards
    data = dashboard_import_export.export_dashboards(db.session)
  File "/opt/superset/venv/lib64/python3.8/site-packages/superset/utils/dashboard_import_export.py", line 31, in export_dashboards
    for dashboard in dashboards:
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/orm/query.py", line 3535, in __iter__
    return self._execute_and_instances(context)
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
    return meth(self, multiparams, params)
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
    ret = self._execute_context(
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
    self._handle_dbapi_exception(
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception
    util.raise_(
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
    raise exception
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
    self.dialect.do_execute(
  File "/opt/superset/venv/lib64/python3.8/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: dashboards
[SQL: SELECT dashboards.uuid AS dashboards_uuid, dashboards.created_on AS dashboards_created_on, dashboards.changed_on AS dashboards_changed_on, dashboards.id AS dashboards_id, dashboards.dashboard_title AS dashboards_dashboard_title, dashboards.position_json AS dashboards_position_json, dashboards.description AS dashboards_description, dashboards.css AS dashboards_css, dashboards.json_metadata AS dashboards_json_metadata, dashboards.slug AS dashboards_slug, dashboards.published AS dashboards_published, dashboards.created_by_fk AS dashboards_created_by_fk, dashboards.changed_by_fk AS dashboards_changed_by_fk 
FROM dashboards]
(Background on this error at: http://sqlalche.me/e/13/e3q8)

Here, Superset seems to look for dashboards in a SQLite db… yet I've been using PostgreSQL as back-end database (and have defined dashboards in my instance that's running otherwise smoothly):

$ cat /opt/superset/superset_config.py | grep -C 0 SQLALCHEMY_DATABASE_URI
SQLALCHEMY_DATABASE_URI = 'postgresql://superset:<password>@localhost/superset_backend'

@krsnik93
Copy link
Contributor Author

Closing as I am now able to do superset export-dashboards followed by superset import-dashboards, as well as superset export-datasources followed by superset import-datasources, on latest master without errors.

@krsnik93
Copy link
Contributor Author

This happens if you run superset export-dashboards without having created an admin user with superset fab create-admin

@tooptoop4
Copy link
Contributor

superset export-datasources gives me this error on 2.0.1

@rafmagns-skepa-dreag
Copy link

I had this problem on 2.1.0 but was able to solve it by running superset fab create-admin as suggested above. not sure why this was necessary as there were 4 admin users that already existed but none had been created by that command

@Sopholos
Copy link

Sopholos commented Jul 7, 2024

I had same problem on 3.1.2 and finally discovered that issue happens when there are no user with login "admin", because of CLI exporting using this user

g.user = security_manager.find_user(username="admin")

so to fix this issue you just need to create user with "admin" login and access enough to export

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dashboard:export Related to exporting dashboards question & help wanted Use Github discussions instead
Projects
None yet
Development

No branches or pull requests

7 participants