升级Apache Superset后出现错误-RuntimeError:在应用程序上下文之外工作

问题描述

我刚刚升级到Apache Superset的最新版本。 当我使用命令启动Apache Superset时

gunicorn \
      -w 10 \
      -k gevent \
      --timeout 120 \
      -b  0.0.0.0:8088 \
      --limit-request-line 0 \
      --limit-request-field_size 0 \
      --statsd-host localhost:8088 \
      superset:app

我收到错误“内部服务器错误” 在服务器上显示

 respiter = self.wsgi(environ,resp.start_response)
  File "/usr/local/superset/lib/python3.7/site-packages/werkzeug/local.py",line 376,in <lambda>
    __call__ = lambda x,*a,**kw: x._get_current_object()(*a,**kw)
  File "/usr/local/superset/lib/python3.7/site-packages/werkzeug/local.py",line 307,in _get_current_object
    return self.__local()
  File "/usr/local/superset/lib/python3.7/site-packages/flask/globals.py",line 52,in _find_app
    raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.
This typically means that you attempted to use functionality that needed
to interface with the current application object in some way. To solve
this,set up an application context with app.app_context().  See the
documentation for more information.

...

我发现我可以将其更改为“ superset.app:create_app()”,如下所示:

gunicorn \
      -w 10 \
      -k gevent \
      --timeout 120 \
      -b  0.0.0.0:8088 \
      --limit-request-line 0 \
      --limit-request-field_size 0 \
      --statsd-host localhost:8088 \
"superset.app:create_app()"

但是当我打开仪表板时,现在出现此错误

 File "/usr/local/superset/lib/python3.7/site-packages/MysqLdb/connections.py",line 239,in query
    _MysqL.connection.query(self,query)
sqlalchemy.exc.OperationalError: (MysqLdb._exceptions.OperationalError) (1054,"UnkNown column 'slices.schema_perm' in 'field list'")
[sql: SELECT slices.created_on AS slices_created_on,slices.changed_on AS slices_changed_on,slices.id AS slices_id,slices.slice_name AS slices_slice_name,slices.datasource_id AS slices_datasource_id,slices.datasource_type AS slices_datasource_type,slices.datasource_name AS slices_datasource_name,slices.viz_type AS slices_viz_type,slices.params AS slices_params,slices.description AS slices_description,slices.cache_timeout AS slices_cache_timeout,slices.perm AS slices_perm,slices.schema_perm AS slices_schema_perm,slices.created_by_fk AS slices_created_by_fk,slices.changed_by_fk AS slices_changed_by_fk,tables_1.created_on AS tables_1_created_on,tables_1.changed_on AS tables_1_changed_on,tables_1.id AS tables_1_id,tables_1.description AS tables_1_description,tables_1.default_endpoint AS tables_1_default_endpoint,tables_1.is_featured AS tables_1_is_featured,tables_1.filter_select_enabled AS tables_1_filter_select_enabled,tables_1.offset AS tables_1_offset,tables_1.cache_timeout AS tables_1_cache_timeout,tables_1.params AS tables_1_params,tables_1.perm AS tables_1_perm,tables_1.schema_perm AS tables_1_schema_perm,tables_1.table_name AS tables_1_table_name,tables_1.main_dttm_col AS tables_1_main_dttm_col,tables_1.database_id AS tables_1_database_id,tables_1.fetch_values_predicate AS tables_1_fetch_values_predicate,tables_1.`schema` AS tables_1_schema,tables_1.`sql` AS tables_1_sql,tables_1.is_sqllab_view AS tables_1_is_sqllab_view,tables_1.template_params AS tables_1_template_params,tables_1.created_by_fk AS tables_1_created_by_fk,tables_1.changed_by_fk AS tables_1_changed_by_fk 
FROM dashboard_slices,slices LEFT OUTER JOIN `tables` AS tables_1 ON slices.datasource_id = tables_1.id AND slices.datasource_type = %s 
WHERE %s = dashboard_slices.dashboard_id AND slices.id = dashboard_slices.slice_id]
[parameters: ('table',7)]
(Background on this error at: http://sqlalche.me/e/13/e3q8)

我已经搜索了更多的解决方案。似乎在使用db upgrade命令时,MysqL数据库没有通过升级得到纠正:

(superset) [root@host .superset]# superset db upgrade
logging was configured successfully
INFO:superset.utils.logging_configurator:logging was configured successfully
/usr/local/superset/lib/python3.7/site-packages/flask_caching/__init__.py:188: UserWarning: Flask-Cache: CACHE_TYPE is set to null,caching is effectively disabled.
  warnings.warn("Flask-Cache: CACHE_TYPE is set to null,"
WARNI [alembic.env] sqlite Database support for Metadata databases will         be removed in a future version of Superset.
INFO  [alembic.runtime.migration] Context impl sqliteImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.

我没有看到任何错误吗?

当我调用init时,我得到了:

(superset) [root@host .superset]# superset init
logging was configured successfully
INFO:superset.utils.logging_configurator:logging was configured successfully
/usr/local/superset/lib/python3.7/site-packages/flask_caching/__init__.py:188: UserWarning: Flask-Cache: CACHE_TYPE is set to null,"
Syncing role deFinition
INFO:superset.security.manager:Syncing role deFinition
Syncing Admin perms
INFO:superset.security.manager:Syncing Admin perms
Syncing Alpha perms
INFO:superset.security.manager:Syncing Alpha perms
Syncing Gamma perms
INFO:superset.security.manager:Syncing Gamma perms
Syncing granter perms
INFO:superset.security.manager:Syncing granter perms
Syncing sql_lab perms
INFO:superset.security.manager:Syncing sql_lab perms
Fetching a set of all perms to lookup which ones are missing
INFO:superset.security.manager:Fetching a set of all perms to lookup which ones are missing
Creating missing datasource permissions.
INFO:superset.security.manager:Creating missing datasource permissions.
Creating missing database permissions.
INFO:superset.security.manager:Creating missing database permissions.
Creating missing metrics permissions
INFO:superset.security.manager:Creating missing metrics permissions
Cleaning faulty perms
INFO:superset.security.manager:Cleaning faulty perms

是因为超集需要MysqL的某些权限才能在表中进行更改?

希望有人可以进一步帮助我

谢谢

解决方法

我不知道为什么命令“ superset db upgrade”没有更新我的MYSQL数据库,但是我随后手动创建了这些字段和表,现在看来可以正常工作:

slices.schema_perm
tables.schema_perm
dbs.encrypted_extra
dbs.allow_cvas
dbs.server_cert
saved_query.extra_json

这些带有字段的表

CREATE TABLE `alerts` (
  `id` int(11) NOT NULL,`label` varchar(250) DEFAULT NULL,`active` tinyint(2) DEFAULT NULL,`crontab` varchar(250) DEFAULT NULL,`sql` varchar(250) DEFAULT NULL,`alert_type` varchar(250) DEFAULT NULL,`recipients` varchar(250) DEFAULT NULL,`log_retention` varchar(250) DEFAULT NULL,`grace_period` varchar(250) DEFAULT NULL,`slice_id` int(11) DEFAULT NULL,`dashboard_id` int(11) DEFAULT NULL,`database_id` int(11) DEFAULT NULL,`last_eval_dttm` varchar(250) DEFAULT NULL,`last_state` varchar(250) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

ALTER TABLE `alerts`
  ADD PRIMARY KEY (`id`);

CREATE TABLE `tab_state` (
  `created_on` datetime DEFAULT NULL,`changed_on` datetime DEFAULT NULL,`extra_json` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,`id` int(11) NOT NULL,`user_id` int(11) NOT NULL,`label` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,`active` tinyint(1) DEFAULT NULL,`database_id` int(11) NOT NULL,`schema` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,`sql` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,`query_limit` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,`latest_query_id` int(11) NOT NULL,`autorun` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,`template_params` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,`created_by_fk` int(11) NOT NULL,`changed_by_fk` int(11) NOT NULL,) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

我不知道字段类型,所以也许有人可以为您提供正确的类型。

谢谢