diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 049503bbb..a0801792a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -110,7 +110,7 @@ For large features or major changes to codebase, please create **Superset Improv ### Fix Bugs Look through the GitHub issues. Issues tagged with `#bug` are -open to whoever wants to implement it. +open to whoever wants to implement them. ### Implement Features diff --git a/superset/__init__.py b/superset/__init__.py index 0feaca91f..01d98f55f 100644 --- a/superset/__init__.py +++ b/superset/__init__.py @@ -35,7 +35,7 @@ from superset import config from superset.connectors.connector_registry import ConnectorRegistry from superset.security import SupersetSecurityManager from superset.utils.core import pessimistic_connection_handling, setup_cache -from superset.utils.log import DBEventLogger, get_event_logger_from_cfg_value +from superset.utils.log import get_event_logger_from_cfg_value wtforms_json.init() @@ -132,19 +132,19 @@ migrate = Migrate(app, db, directory=APP_DIR + "/migrations") app.config["LOGGING_CONFIGURATOR"].configure_logging(app.config, app.debug) -if app.config.get("ENABLE_CORS"): +if app.config["ENABLE_CORS"]: from flask_cors import CORS - CORS(app, **app.config.get("CORS_OPTIONS")) + CORS(app, **app.config["CORS_OPTIONS"]) -if app.config.get("ENABLE_PROXY_FIX"): +if app.config["ENABLE_PROXY_FIX"]: from werkzeug.middleware.proxy_fix import ProxyFix app.wsgi_app = ProxyFix( # type: ignore - app.wsgi_app, **app.config.get("PROXY_FIX_CONFIG") + app.wsgi_app, **app.config["PROXY_FIX_CONFIG"] ) -if app.config.get("ENABLE_CHUNK_ENCODING"): +if app.config["ENABLE_CHUNK_ENCODING"]: class ChunkedEncodingFix(object): def __init__(self, app): @@ -175,7 +175,7 @@ class MyIndexView(IndexView): return redirect("/superset/welcome") -custom_sm = app.config.get("CUSTOM_SECURITY_MANAGER") or SupersetSecurityManager +custom_sm = app.config["CUSTOM_SECURITY_MANAGER"] or SupersetSecurityManager if not issubclass(custom_sm, SupersetSecurityManager): raise Exception( """Your CUSTOM_SECURITY_MANAGER must now extend SupersetSecurityManager, @@ -195,21 +195,19 @@ with app.app_context(): security_manager = appbuilder.sm -results_backend = app.config.get("RESULTS_BACKEND") -results_backend_use_msgpack = app.config.get("RESULTS_BACKEND_USE_MSGPACK") +results_backend = app.config["RESULTS_BACKEND"] +results_backend_use_msgpack = app.config["RESULTS_BACKEND_USE_MSGPACK"] # Merge user defined feature flags with default feature flags -_feature_flags = app.config.get("DEFAULT_FEATURE_FLAGS") or {} -_feature_flags.update(app.config.get("FEATURE_FLAGS") or {}) +_feature_flags = app.config["DEFAULT_FEATURE_FLAGS"] +_feature_flags.update(app.config["FEATURE_FLAGS"]) # Event Logger -event_logger = get_event_logger_from_cfg_value( - app.config.get("EVENT_LOGGER", DBEventLogger()) -) +event_logger = get_event_logger_from_cfg_value(app.config["EVENT_LOGGER"]) def get_feature_flags(): - GET_FEATURE_FLAGS_FUNC = app.config.get("GET_FEATURE_FLAGS_FUNC") + GET_FEATURE_FLAGS_FUNC = app.config["GET_FEATURE_FLAGS_FUNC"] if GET_FEATURE_FLAGS_FUNC: return GET_FEATURE_FLAGS_FUNC(deepcopy(_feature_flags)) return _feature_flags @@ -232,7 +230,7 @@ if app.config["TALISMAN_ENABLED"]: # Hook that provides administrators a handle on the Flask APP # after initialization -flask_app_mutator = app.config.get("FLASK_APP_MUTATOR") +flask_app_mutator = app.config["FLASK_APP_MUTATOR"] if flask_app_mutator: flask_app_mutator(app) diff --git a/superset/cli.py b/superset/cli.py index a32449eeb..8e695bbf2 100755 --- a/superset/cli.py +++ b/superset/cli.py @@ -62,7 +62,7 @@ def version(verbose): Fore.YELLOW + "Superset " + Fore.CYAN - + "{version}".format(version=config.get("VERSION_STRING")) + + "{version}".format(version=config["VERSION_STRING"]) ) print(Fore.BLUE + "-=" * 15) if verbose: @@ -372,10 +372,8 @@ def worker(workers): ) if workers: celery_app.conf.update(CELERYD_CONCURRENCY=workers) - elif config.get("SUPERSET_CELERY_WORKERS"): - celery_app.conf.update( - CELERYD_CONCURRENCY=config.get("SUPERSET_CELERY_WORKERS") - ) + elif config["SUPERSET_CELERY_WORKERS"]: + celery_app.conf.update(CELERYD_CONCURRENCY=config["SUPERSET_CELERY_WORKERS"]) worker = celery_app.Worker(optimization="fair") worker.start() @@ -428,7 +426,7 @@ def load_test_users_run(): Syncs permissions for those users/roles """ - if config.get("TESTING"): + if config["TESTING"]: sm = security_manager diff --git a/superset/common/query_object.py b/superset/common/query_object.py index b2822e37d..21649d1d0 100644 --- a/superset/common/query_object.py +++ b/superset/common/query_object.py @@ -66,8 +66,8 @@ class QueryObject: extras: Optional[Dict] = None, columns: Optional[List[str]] = None, orderby: Optional[List[List]] = None, - relative_start: str = app.config.get("DEFAULT_RELATIVE_START_TIME", "today"), - relative_end: str = app.config.get("DEFAULT_RELATIVE_END_TIME", "today"), + relative_start: str = app.config["DEFAULT_RELATIVE_START_TIME"], + relative_end: str = app.config["DEFAULT_RELATIVE_END_TIME"], ): self.granularity = granularity self.from_dttm, self.to_dttm = utils.get_since_until( diff --git a/superset/config.py b/superset/config.py index bf2deac51..b6b2b1fa3 100644 --- a/superset/config.py +++ b/superset/config.py @@ -35,10 +35,14 @@ from dateutil import tz from flask_appbuilder.security.manager import AUTH_DB from superset.stats_logger import DummyStatsLogger +from superset.utils.log import DBEventLogger from superset.utils.logging_configurator import DefaultLoggingConfigurator # Realtime stats logger, a StatsD implementation exists STATS_LOGGER = DummyStatsLogger() +EVENT_LOGGER = DBEventLogger() + +SUPERSET_LOG_VIEW = True BASE_DIR = os.path.abspath(os.path.dirname(__file__)) if "SUPERSET_HOME" in os.environ: @@ -109,6 +113,7 @@ SQLALCHEMY_DATABASE_URI = "sqlite:///" + os.path.join(DATA_DIR, "superset.db") # def lookup_password(url): # return 'secret' # SQLALCHEMY_CUSTOM_PASSWORD_STORE = lookup_password +SQLALCHEMY_CUSTOM_PASSWORD_STORE = None # The limit of queries fetched for query search QUERY_SEARCH_LIMIT = 1000 @@ -232,6 +237,9 @@ DEFAULT_FEATURE_FLAGS = { "PRESTO_EXPAND_DATA": False, } +# This is merely a default. +FEATURE_FLAGS: Dict[str, bool] = {} + # A function that receives a dict of all feature flags # (DEFAULT_FEATURE_FLAGS merged with FEATURE_FLAGS) # can alter it, and returns a similar dict. Note the dict of feature @@ -371,6 +379,7 @@ BACKUP_COUNT = 30 # security_manager=None, # ): # pass +QUERY_LOGGER = None # Set this API key to enable Mapbox visualizations MAPBOX_API_KEY = os.environ.get("MAPBOX_API_KEY", "") @@ -444,6 +453,7 @@ CELERY_CONFIG = CeleryConfig # override anything set within the app DEFAULT_HTTP_HEADERS: Dict[str, Any] = {} OVERRIDE_HTTP_HEADERS: Dict[str, Any] = {} +HTTP_HEADERS: Dict[str, Any] = {} # The db id here results in selecting this one as a default in SQL Lab DEFAULT_DB_ID = None @@ -522,13 +532,18 @@ SMTP_PASSWORD = "superset" SMTP_MAIL_FROM = "superset@superset.com" if not CACHE_DEFAULT_TIMEOUT: - CACHE_DEFAULT_TIMEOUT = CACHE_CONFIG.get("CACHE_DEFAULT_TIMEOUT") # type: ignore + CACHE_DEFAULT_TIMEOUT = CACHE_CONFIG["CACHE_DEFAULT_TIMEOUT"] + + +ENABLE_CHUNK_ENCODING = False # Whether to bump the logging level to ERROR on the flask_appbuilder package # Set to False if/when debugging FAB related issues like # permission management SILENCE_FAB = True +FAB_ADD_SECURITY_VIEWS = True + # The link to a page containing common errors and their resolutions # It will be appended at the bottom of sql_lab errors. TROUBLESHOOTING_LINK = "" diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py index dee7ccb8b..ef054bcf6 100644 --- a/superset/connectors/sqla/models.py +++ b/superset/connectors/sqla/models.py @@ -563,7 +563,7 @@ class SqlaTable(Model, BaseDatasource): """Apply config's SQL_QUERY_MUTATOR Typically adds comments to the query with context""" - SQL_QUERY_MUTATOR = config.get("SQL_QUERY_MUTATOR") + SQL_QUERY_MUTATOR = config["SQL_QUERY_MUTATOR"] if SQL_QUERY_MUTATOR: username = utils.get_username() sql = SQL_QUERY_MUTATOR(sql, username, security_manager, self.database) diff --git a/superset/db_engine_specs/base.py b/superset/db_engine_specs/base.py index 2939f3952..2ccb24555 100644 --- a/superset/db_engine_specs/base.py +++ b/superset/db_engine_specs/base.py @@ -183,7 +183,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods ret_list = [] time_grain_functions = cls.get_time_grain_functions() time_grains = builtin_time_grains.copy() - time_grains.update(config.get("TIME_GRAIN_ADDONS", {})) + time_grains.update(config["TIME_GRAIN_ADDONS"]) for duration, func in time_grain_functions.items(): if duration in time_grains: name = time_grains[duration] @@ -200,9 +200,9 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods """ # TODO: use @memoize decorator or similar to avoid recomputation on every call time_grain_functions = cls._time_grain_functions.copy() - grain_addon_functions = config.get("TIME_GRAIN_ADDON_FUNCTIONS", {}) + grain_addon_functions = config["TIME_GRAIN_ADDON_FUNCTIONS"] time_grain_functions.update(grain_addon_functions.get(cls.engine, {})) - blacklist: List[str] = config.get("TIME_GRAIN_BLACKLIST", []) + blacklist: List[str] = config["TIME_GRAIN_BLACKLIST"] for key in blacklist: time_grain_functions.pop(key) return time_grain_functions diff --git a/superset/db_engine_specs/hive.py b/superset/db_engine_specs/hive.py index c826a3090..712af14da 100644 --- a/superset/db_engine_specs/hive.py +++ b/superset/db_engine_specs/hive.py @@ -122,16 +122,16 @@ class HiveEngineSpec(PrestoEngineSpec): table_name = form.name.data schema_name = form.schema.data - if config.get("UPLOADED_CSV_HIVE_NAMESPACE"): + if config["UPLOADED_CSV_HIVE_NAMESPACE"]: if "." in table_name or schema_name: raise Exception( "You can't specify a namespace. " "All tables will be uploaded to the `{}` namespace".format( - config.get("HIVE_NAMESPACE") + config["HIVE_NAMESPACE"] ) ) full_table_name = "{}.{}".format( - config.get("UPLOADED_CSV_HIVE_NAMESPACE"), table_name + config["UPLOADED_CSV_HIVE_NAMESPACE"], table_name ) else: if "." in table_name and schema_name: diff --git a/superset/db_engine_specs/presto.py b/superset/db_engine_specs/presto.py index ffe0de3ab..a3569371b 100644 --- a/superset/db_engine_specs/presto.py +++ b/superset/db_engine_specs/presto.py @@ -455,7 +455,7 @@ class PrestoEngineSpec(BaseEngineSpec): parsed_query = ParsedQuery(statement) sql = parsed_query.stripped() - sql_query_mutator = config.get("SQL_QUERY_MUTATOR") + sql_query_mutator = config["SQL_QUERY_MUTATOR"] if sql_query_mutator: sql = sql_query_mutator(sql, user_name, security_manager, database) diff --git a/superset/examples/birth_names.py b/superset/examples/birth_names.py index bad084d8a..ec79dd70d 100644 --- a/superset/examples/birth_names.py +++ b/superset/examples/birth_names.py @@ -122,7 +122,7 @@ def load_birth_names(only_metadata=False, force=False): "optionName": "metric_11", } ], - "row_limit": config.get("ROW_LIMIT"), + "row_limit": config["ROW_LIMIT"], "since": "100 years ago", "until": "now", "viz_type": "table", diff --git a/superset/examples/multiformat_time_series.py b/superset/examples/multiformat_time_series.py index 4a03f967d..84ac93e26 100644 --- a/superset/examples/multiformat_time_series.py +++ b/superset/examples/multiformat_time_series.py @@ -95,7 +95,7 @@ def load_multiformat_time_series(only_metadata=False, force=False): slice_data = { "metrics": ["count"], "granularity_sqla": col.column_name, - "row_limit": config.get("ROW_LIMIT"), + "row_limit": config["ROW_LIMIT"], "since": "2015", "until": "2016", "where": "", diff --git a/superset/examples/random_time_series.py b/superset/examples/random_time_series.py index 2e8f51f7b..eb1e82721 100644 --- a/superset/examples/random_time_series.py +++ b/superset/examples/random_time_series.py @@ -58,7 +58,7 @@ def load_random_time_series_data(only_metadata=False, force=False): slice_data = { "granularity_sqla": "day", - "row_limit": config.get("ROW_LIMIT"), + "row_limit": config["ROW_LIMIT"], "since": "1 year ago", "until": "now", "metric": "count", diff --git a/superset/examples/unicode_test_data.py b/superset/examples/unicode_test_data.py index 1c88456c8..14e691852 100644 --- a/superset/examples/unicode_test_data.py +++ b/superset/examples/unicode_test_data.py @@ -87,7 +87,7 @@ def load_unicode_test_data(only_metadata=False, force=False): "expressionType": "SIMPLE", "label": "Value", }, - "row_limit": config.get("ROW_LIMIT"), + "row_limit": config["ROW_LIMIT"], "since": "100 years ago", "until": "now", "where": "", diff --git a/superset/examples/world_bank.py b/superset/examples/world_bank.py index 699eb7045..34cb394b1 100644 --- a/superset/examples/world_bank.py +++ b/superset/examples/world_bank.py @@ -104,7 +104,7 @@ def load_world_bank_health_n_pop(only_metadata=False, force=False): "groupby": [], "metric": "sum__SP_POP_TOTL", "metrics": ["sum__SP_POP_TOTL"], - "row_limit": config.get("ROW_LIMIT"), + "row_limit": config["ROW_LIMIT"], "since": "2014-01-01", "until": "2014-01-02", "time_range": "2014-01-01 : 2014-01-02", diff --git a/superset/jinja_context.py b/superset/jinja_context.py index c48218a54..f522de344 100644 --- a/superset/jinja_context.py +++ b/superset/jinja_context.py @@ -39,7 +39,7 @@ BASE_CONTEXT = { "timedelta": timedelta, "uuid": uuid, } -BASE_CONTEXT.update(config.get("JINJA_CONTEXT_ADDONS", {})) +BASE_CONTEXT.update(config["JINJA_CONTEXT_ADDONS"]) def url_param(param: str, default: Optional[str] = None) -> Optional[Any]: diff --git a/superset/migrations/env.py b/superset/migrations/env.py index 7e647d906..2e81bc06b 100755 --- a/superset/migrations/env.py +++ b/superset/migrations/env.py @@ -33,9 +33,7 @@ fileConfig(config.config_file_name) logger = logging.getLogger("alembic.env") -config.set_main_option( - "sqlalchemy.url", current_app.config.get("SQLALCHEMY_DATABASE_URI") -) +config.set_main_option("sqlalchemy.url", current_app.config["SQLALCHEMY_DATABASE_URI"]) target_metadata = Base.metadata # pylint: disable=no-member # other values from the config, defined by the needs of env.py, diff --git a/superset/models/core.py b/superset/models/core.py index c9b63da44..a177d26c0 100755 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -63,9 +63,9 @@ from superset.utils import cache as cache_util, core as utils from superset.viz import viz_types config = app.config -custom_password_store = config.get("SQLALCHEMY_CUSTOM_PASSWORD_STORE") -stats_logger = config.get("STATS_LOGGER") -log_query = config.get("QUERY_LOGGER") +custom_password_store = config["SQLALCHEMY_CUSTOM_PASSWORD_STORE"] +stats_logger = config["STATS_LOGGER"] +log_query = config["QUERY_LOGGER"] metadata = Model.metadata # pylint: disable=no-member PASSWORD_MASK = "X" * 10 @@ -81,7 +81,7 @@ def set_related_perm(mapper, connection, target): def copy_dashboard(mapper, connection, target): - dashboard_id = config.get("DASHBOARD_TEMPLATE_ID") + dashboard_id = config["DASHBOARD_TEMPLATE_ID"] if dashboard_id is None: return @@ -725,7 +725,7 @@ class Database(Model, AuditMixinNullable, ImportMixin): # short unique name, used in permissions database_name = Column(String(250), unique=True, nullable=False) sqlalchemy_uri = Column(String(1024)) - password = Column(EncryptedType(String(1024), config.get("SECRET_KEY"))) + password = Column(EncryptedType(String(1024), config["SECRET_KEY"])) cache_timeout = Column(Integer) select_as_create_table_as = Column(Boolean, default=False) expose_in_sqllab = Column(Boolean, default=True) @@ -906,7 +906,7 @@ class Database(Model, AuditMixinNullable, ImportMixin): params.update(self.get_encrypted_extra()) - DB_CONNECTION_MUTATOR = config.get("DB_CONNECTION_MUTATOR") + DB_CONNECTION_MUTATOR = config["DB_CONNECTION_MUTATOR"] if DB_CONNECTION_MUTATOR: url, params = DB_CONNECTION_MUTATOR( url, params, effective_username, security_manager, source @@ -1262,7 +1262,7 @@ class DatasourceAccessRequest(Model, AuditMixinNullable): datasource_id = Column(Integer) datasource_type = Column(String(200)) - ROLES_BLACKLIST = set(config.get("ROBOT_PERMISSION_ROLES", [])) + ROLES_BLACKLIST = set(config["ROBOT_PERMISSION_ROLES"]) @property def cls_model(self): diff --git a/superset/sql_lab.py b/superset/sql_lab.py index 575a10d4d..f64a4307d 100644 --- a/superset/sql_lab.py +++ b/superset/sql_lab.py @@ -50,10 +50,10 @@ from superset.utils.dates import now_as_float from superset.utils.decorators import stats_timing config = app.config -stats_logger = config.get("STATS_LOGGER") -SQLLAB_TIMEOUT = config.get("SQLLAB_ASYNC_TIME_LIMIT_SEC", 600) +stats_logger = config["STATS_LOGGER"] +SQLLAB_TIMEOUT = config["SQLLAB_ASYNC_TIME_LIMIT_SEC"] SQLLAB_HARD_TIMEOUT = SQLLAB_TIMEOUT + 60 -log_query = config.get("QUERY_LOGGER") +log_query = config["QUERY_LOGGER"] class SqlLabException(Exception): @@ -114,7 +114,7 @@ def session_scope(nullpool): """Provide a transactional scope around a series of operations.""" if nullpool: engine = sqlalchemy.create_engine( - app.config.get("SQLALCHEMY_DATABASE_URI"), poolclass=NullPool + app.config["SQLALCHEMY_DATABASE_URI"], poolclass=NullPool ) session_class = sessionmaker() session_class.configure(bind=engine) @@ -179,7 +179,7 @@ def execute_sql_statement(sql_statement, query, user_name, session, cursor): db_engine_spec = database.db_engine_spec parsed_query = ParsedQuery(sql_statement) sql = parsed_query.stripped() - SQL_MAX_ROWS = app.config.get("SQL_MAX_ROW") + SQL_MAX_ROWS = app.config["SQL_MAX_ROW"] if not parsed_query.is_readonly() and not database.allow_dml: raise SqlLabSecurityException( @@ -207,7 +207,7 @@ def execute_sql_statement(sql_statement, query, user_name, session, cursor): sql = database.apply_limit_to_sql(sql, query.limit) # Hook to allow environment-specific mutation (usually comments) to the SQL - SQL_QUERY_MUTATOR = config.get("SQL_QUERY_MUTATOR") + SQL_QUERY_MUTATOR = config["SQL_QUERY_MUTATOR"] if SQL_QUERY_MUTATOR: sql = SQL_QUERY_MUTATOR(sql, user_name, security_manager, database) @@ -408,7 +408,7 @@ def execute_sql_statements( ) cache_timeout = database.cache_timeout if cache_timeout is None: - cache_timeout = config.get("CACHE_DEFAULT_TIMEOUT", 0) + cache_timeout = config["CACHE_DEFAULT_TIMEOUT"] compressed = zlib_compress(serialized_payload) logging.debug( diff --git a/superset/sql_validators/presto_db.py b/superset/sql_validators/presto_db.py index f684db652..90d22f0e6 100644 --- a/superset/sql_validators/presto_db.py +++ b/superset/sql_validators/presto_db.py @@ -52,7 +52,7 @@ class PrestoDBSQLValidator(BaseSQLValidator): # Hook to allow environment-specific mutation (usually comments) to the SQL # pylint: disable=invalid-name - SQL_QUERY_MUTATOR = config.get("SQL_QUERY_MUTATOR") + SQL_QUERY_MUTATOR = config["SQL_QUERY_MUTATOR"] if SQL_QUERY_MUTATOR: sql = SQL_QUERY_MUTATOR(sql, user_name, security_manager, database) diff --git a/superset/tasks/schedules.py b/superset/tasks/schedules.py index 6bda5b7ba..64d9b4dc5 100644 --- a/superset/tasks/schedules.py +++ b/superset/tasks/schedules.py @@ -60,7 +60,7 @@ EmailContent = namedtuple("EmailContent", ["body", "data", "images"]) def _get_recipients(schedule): - bcc = config.get("EMAIL_REPORT_BCC_ADDRESS", None) + bcc = config["EMAIL_REPORT_BCC_ADDRESS"] if schedule.deliver_as_group: to = schedule.recipients @@ -81,7 +81,7 @@ def _deliver_email(schedule, subject, email): images=email.images, bcc=bcc, mime_subtype="related", - dryrun=config.get("SCHEDULED_EMAIL_DEBUG_MODE"), + dryrun=config["SCHEDULED_EMAIL_DEBUG_MODE"], ) @@ -97,7 +97,7 @@ def _generate_mail_content(schedule, screenshot, name, url): elif schedule.delivery_type == EmailDeliveryType.inline: # Get the domain from the 'From' address .. # and make a message id without the < > in the ends - domain = parseaddr(config.get("SMTP_MAIL_FROM"))[1].split("@")[1] + domain = parseaddr(config["SMTP_MAIL_FROM"])[1].split("@")[1] msgid = make_msgid(domain)[1:-1] images = {msgid: screenshot} @@ -118,7 +118,7 @@ def _generate_mail_content(schedule, screenshot, name, url): def _get_auth_cookies(): # Login with the user specified to get the reports with app.test_request_context(): - user = security_manager.find_user(config.get("EMAIL_REPORTS_USER")) + user = security_manager.find_user(config["EMAIL_REPORTS_USER"]) login_user(user) # A mock response object to get the cookie information from @@ -139,16 +139,16 @@ def _get_auth_cookies(): def _get_url_path(view, **kwargs): with app.test_request_context(): return urllib.parse.urljoin( - str(config.get("WEBDRIVER_BASEURL")), url_for(view, **kwargs) + str(config["WEBDRIVER_BASEURL"]), url_for(view, **kwargs) ) def create_webdriver(): # Create a webdriver for use in fetching reports - if config.get("EMAIL_REPORTS_WEBDRIVER") == "firefox": + if config["EMAIL_REPORTS_WEBDRIVER"] == "firefox": driver_class = firefox.webdriver.WebDriver options = firefox.options.Options() - elif config.get("EMAIL_REPORTS_WEBDRIVER") == "chrome": + elif config["EMAIL_REPORTS_WEBDRIVER"] == "chrome": driver_class = chrome.webdriver.WebDriver options = chrome.options.Options() @@ -156,7 +156,7 @@ def create_webdriver(): # Prepare args for the webdriver init kwargs = dict(options=options) - kwargs.update(config.get("WEBDRIVER_CONFIGURATION")) + kwargs.update(config["WEBDRIVER_CONFIGURATION"]) # Initialize the driver driver = driver_class(**kwargs) @@ -208,7 +208,7 @@ def deliver_dashboard(schedule): # Create a driver, fetch the page, wait for the page to render driver = create_webdriver() - window = config.get("WEBDRIVER_WINDOW")["dashboard"] + window = config["WEBDRIVER_WINDOW"]["dashboard"] driver.set_window_size(*window) driver.get(dashboard_url) time.sleep(PAGE_RENDER_WAIT) @@ -236,7 +236,7 @@ def deliver_dashboard(schedule): subject = __( "%(prefix)s %(title)s", - prefix=config.get("EMAIL_REPORTS_SUBJECT_PREFIX"), + prefix=config["EMAIL_REPORTS_SUBJECT_PREFIX"], title=dashboard.dashboard_title, ) @@ -296,7 +296,7 @@ def _get_slice_visualization(schedule): # Create a driver, fetch the page, wait for the page to render driver = create_webdriver() - window = config.get("WEBDRIVER_WINDOW")["slice"] + window = config["WEBDRIVER_WINDOW"]["slice"] driver.set_window_size(*window) slice_url = _get_url_path("Superset.slice", slice_id=slc.id) @@ -339,7 +339,7 @@ def deliver_slice(schedule): subject = __( "%(prefix)s %(title)s", - prefix=config.get("EMAIL_REPORTS_SUBJECT_PREFIX"), + prefix=config["EMAIL_REPORTS_SUBJECT_PREFIX"], title=schedule.slice.slice_name, ) @@ -413,11 +413,11 @@ def schedule_window(report_type, start_at, stop_at, resolution): def schedule_hourly(): """ Celery beat job meant to be invoked hourly """ - if not config.get("ENABLE_SCHEDULED_EMAIL_REPORTS"): + if not config["ENABLE_SCHEDULED_EMAIL_REPORTS"]: logging.info("Scheduled email reports not enabled in config") return - resolution = config.get("EMAIL_REPORTS_CRON_RESOLUTION", 0) * 60 + resolution = config["EMAIL_REPORTS_CRON_RESOLUTION"] * 60 # Get the top of the hour start_at = datetime.now(tzlocal()).replace(microsecond=0, second=0, minute=0) diff --git a/superset/templates/appbuilder/navbar.html b/superset/templates/appbuilder/navbar.html index 72eefdfc5..312596657 100644 --- a/superset/templates/appbuilder/navbar.html +++ b/superset/templates/appbuilder/navbar.html @@ -18,9 +18,9 @@ #} {% set menu = appbuilder.menu %} {% set languages = appbuilder.languages %} -{% set WARNING_MSG = appbuilder.app.config.get('WARNING_MSG') %} -{% set app_icon_width = appbuilder.app.config.get('APP_ICON_WIDTH', 126) %} -{% set logo_target_path = appbuilder.app.config.get('LOGO_TARGET_PATH') or '/profile/{}/'.format(current_user.username) %} +{% set WARNING_MSG = appbuilder.app.config['WARNING_MSG'] %} +{% set app_icon_width = appbuilder.app.config['APP_ICON_WIDTH'] %} +{% set logo_target_path = appbuilder.app.config['LOGO_TARGET_PATH'] or '/profile/{}/'.format(current_user.username) %} {% set root_path = logo_target_path if not logo_target_path.startswith('/') else '/superset' + logo_target_path if current_user.username is defined else '#' %}