Skip to content

Commit

Permalink
fix(database-import): Support importing a DB connection with a versio…
Browse files Browse the repository at this point in the history
…n set (#26116)

(cherry picked from commit c033ca9)
  • Loading branch information
Vitor-Avila authored and michael-s-molina committed Dec 4, 2023
1 parent ceac19f commit 77332bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions superset/databases/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ def fix_schemas_allowed_for_csv_upload( # pylint: disable=invalid-name
allows_virtual_table_explore = fields.Boolean(required=False)
cancel_query_on_windows_unload = fields.Boolean(required=False)
disable_data_preview = fields.Boolean(required=False)
version = fields.String(required=False, allow_none=True)


class ImportV1DatabaseSchema(Schema):
Expand Down
21 changes: 21 additions & 0 deletions tests/unit_tests/databases/commands/importers/v1/import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# pylint: disable=unused-argument, import-outside-toplevel, invalid-name

import copy
import json

import pytest
from pytest_mock import MockFixture
Expand Down Expand Up @@ -142,3 +143,23 @@ def test_import_database_without_permission(
str(excinfo.value)
== "Database doesn't exist and user doesn't have permission to create databases"
)


def test_import_database_with_version(mocker: MockFixture, session: Session) -> None:
"""
Test importing a database with a version set.
"""
from superset import security_manager
from superset.commands.database.importers.v1.utils import import_database
from superset.models.core import Database
from tests.integration_tests.fixtures.importexport import database_config

mocker.patch.object(security_manager, "can_access", return_value=True)

engine = session.get_bind()
Database.metadata.create_all(engine) # pylint: disable=no-member

config = copy.deepcopy(database_config)
config["extra"]["version"] = "1.1.1"
database = import_database(session, config)
assert json.loads(database.extra)["version"] == "1.1.1"

0 comments on commit 77332bf

Please sign in to comment.