Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Mar 15, 2023
1 parent 1d901ca commit da8a999
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
7 changes: 6 additions & 1 deletion superset/cli/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)
34 changes: 13 additions & 21 deletions superset/commands/importers/v1/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down
4 changes: 3 additions & 1 deletion superset/examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit da8a999

Please sign in to comment.