diff --git a/superset/cli/examples.py b/superset/cli/examples.py index d4ba3af87e531..029b16cc50850 100755 --- a/superset/cli/examples.py +++ b/superset/cli/examples.py @@ -20,6 +20,7 @@ from flask.cli import with_appcontext import superset.utils.database as database_utils +from superset import security_manager logger = logging.getLogger(__name__) @@ -113,4 +114,8 @@ def load_examples( force: bool = False, ) -> None: """Loads a set of Slices and Dashboards and a supporting dataset""" - load_examples_run(load_test_data, load_big_data, only_metadata, force) + # pylint: disable=import-outside-toplevel + from superset.utils.core import override_user + + with override_user(security_manager.find_user(username="admin")): + load_examples_run(load_test_data, load_big_data, only_metadata, force) diff --git a/superset/commands/importers/v1/examples.py b/superset/commands/importers/v1/examples.py index a877f9b02f6b3..f3054063b26fd 100644 --- a/superset/commands/importers/v1/examples.py +++ b/superset/commands/importers/v1/examples.py @@ -16,14 +16,12 @@ # under the License. from typing import Any, Dict, List, Set, Tuple -from flask import current_app -from flask_login import login_user from marshmallow import Schema from sqlalchemy.orm import Session from sqlalchemy.orm.exc import MultipleResultsFound from sqlalchemy.sql import select -from superset import db, security_manager +from superset import db from superset.charts.commands.importers.v1 import ImportChartsCommand from superset.charts.commands.importers.v1.utils import import_chart from superset.charts.schemas import ImportV1ChartSchema @@ -69,24 +67,18 @@ def __init__(self, contents: Dict[str, str], *args: Any, **kwargs: Any): def run(self) -> None: self.validate() - # login as the admin so we have the correct permissions to import everything - admin = security_manager.find_user("admin") - with current_app.app_context(): - with current_app.test_request_context("/login"): - login_user(admin) - - # rollback to prevent partial imports - try: - self._import( - db.session, - self._configs, - self.overwrite, - self.force_data, - ) - db.session.commit() - except Exception as ex: - db.session.rollback() - raise self.import_error() from ex + # rollback to prevent partial imports + try: + self._import( + db.session, + self._configs, + self.overwrite, + self.force_data, + ) + db.session.commit() + except Exception as ex: + db.session.rollback() + raise self.import_error() from ex @classmethod def _get_uuids(cls) -> Set[str]: diff --git a/superset/examples/utils.py b/superset/examples/utils.py index a8316a18c5c0f..8c2cfea23c4e6 100644 --- a/superset/examples/utils.py +++ b/superset/examples/utils.py @@ -92,7 +92,9 @@ def load_configs_from_directory( contents[METADATA_FILE_NAME] = yaml.dump(metadata) command = ImportExamplesCommand( - contents, overwrite=overwrite, force_data=force_data + contents, + overwrite=overwrite, + force_data=force_data, ) try: command.run()