Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Feb 28, 2023
1 parent 9ea8322 commit 3e52f11
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions superset/commands/importers/v1/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
# 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
from superset import db, security_manager
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 @@ -67,13 +69,24 @@ def __init__(self, contents: Dict[str, str], *args: Any, **kwargs: Any):
def run(self) -> None:
self.validate()

# 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
# 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

@classmethod
def _get_uuids(cls) -> Set[str]:
Expand Down

0 comments on commit 3e52f11

Please sign in to comment.