Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Aug 12, 2021
1 parent fcb6d4a commit f956b89
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
16 changes: 15 additions & 1 deletion superset/commands/importers/v1/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,33 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=protected-access

from typing import Any, Dict, List, Tuple
from typing import Any, Dict, List, Set, Tuple

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.charts.commands.importers.v1 import ImportChartsCommand
from superset.charts.commands.importers.v1.utils import import_chart
from superset.charts.schemas import ImportV1ChartSchema
from superset.commands.exceptions import CommandException
from superset.commands.importers.v1 import ImportModelsCommand
from superset.dao.base import BaseDAO
from superset.dashboards.commands.importers.v1 import ImportDashboardsCommand
from superset.dashboards.commands.importers.v1.utils import (
find_chart_uuids,
import_dashboard,
update_id_refs,
)
from superset.dashboards.schemas import ImportV1DashboardSchema
from superset.databases.commands.importers.v1 import ImportDatabasesCommand
from superset.databases.commands.importers.v1.utils import import_database
from superset.databases.schemas import ImportV1DatabaseSchema
from superset.datasets.commands.importers.v1 import ImportDatasetsCommand
from superset.datasets.commands.importers.v1.utils import import_dataset
from superset.datasets.schemas import ImportV1DatasetSchema
from superset.models.core import Database
Expand Down Expand Up @@ -71,6 +76,15 @@ def run(self) -> None:
db.session.rollback()
raise self.import_error()

@classmethod
def _get_uuids(cls) -> Set[str]:
return (
ImportDatabasesCommand._get_uuids()
| ImportDatasetsCommand._get_uuids()
| ImportChartsCommand._get_uuids()
| ImportDashboardsCommand._get_uuids()
)

# pylint: disable=too-many-locals, arguments-differ, too-many-branches
@staticmethod
def _import(
Expand Down
2 changes: 1 addition & 1 deletion superset/dashboards/commands/importers/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def update_id_refs(
child["meta"]["chartId"] = chart_ids[child["meta"]["uuid"]]

# fix native filter references
native_filter_configuration = fixed["metadata"].get(
native_filter_configuration = fixed.get("metadata", {}).get(
"native_filter_configuration", []
)
for native_filter in native_filter_configuration:
Expand Down
3 changes: 1 addition & 2 deletions superset/datasets/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,5 @@ class ImportV1DatasetSchema(Schema):
columns = fields.List(fields.Nested(ImportV1ColumnSchema))
metrics = fields.List(fields.Nested(ImportV1MetricSchema))
version = fields.String(required=True)
# TODO (betodealmeida): disallow None when we have all imports being done by configs
database_uuid = fields.UUID(required=True, allow_none=True)
database_uuid = fields.UUID(required=True)
data = fields.URL()
9 changes: 8 additions & 1 deletion superset/examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import logging
import re
from pathlib import Path
from typing import Any, Dict

import yaml
from pkg_resources import resource_isdir, resource_listdir, resource_stream

from superset.commands.exceptions import CommandInvalidError
from superset.commands.importers.v1.examples import ImportExamplesCommand
from superset.commands.importers.v1.utils import METADATA_FILE_NAME

_logger = logging.getLogger(__name__)

YAML_EXTENSIONS = {".yaml", ".yml"}


Expand Down Expand Up @@ -90,4 +94,7 @@ def load_configs_from_directory(
command = ImportExamplesCommand(
contents, overwrite=overwrite, force_data=force_data
)
command.run()
try:
command.run()
except CommandInvalidError as ex:
_logger.error("An error occurred: %s", ex.normalized_messages())

0 comments on commit f956b89

Please sign in to comment.