This is an automated email from the ASF dual-hosted git repository.

vavila pushed a commit to branch fix/db-import-with-row-expansion
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 8e099989c8e3a50359a22272b55160f95f05a3f4
Author: Vitor Avila <[email protected]>
AuthorDate: Thu Mar 13 15:08:52 2025 -0300

    fix(import): Import a DB connection with expanded rows enabled
---
 superset/databases/schemas.py                  |  1 +
 tests/integration_tests/databases/api_tests.py | 39 ++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/superset/databases/schemas.py b/superset/databases/schemas.py
index c9df9fcbad..bd330b0951 100644
--- a/superset/databases/schemas.py
+++ b/superset/databases/schemas.py
@@ -831,6 +831,7 @@ class ImportV1DatabaseExtraSchema(Schema):
     disable_drill_to_detail = fields.Boolean(required=False)
     allow_multi_catalog = fields.Boolean(required=False)
     version = fields.String(required=False, allow_none=True)
+    schema_options = fields.Dict(keys=fields.Str(), values=fields.Raw())
 
 
 class ImportV1DatabaseSchema(Schema):
diff --git a/tests/integration_tests/databases/api_tests.py 
b/tests/integration_tests/databases/api_tests.py
index 76e76dca18..d633c6e420 100644
--- a/tests/integration_tests/databases/api_tests.py
+++ b/tests/integration_tests/databases/api_tests.py
@@ -3153,6 +3153,45 @@ class TestDatabaseApi(SupersetTestCase):
             ]
         }
 
+    
@mock.patch("superset.commands.database.importers.v1.utils.add_permissions")
+    def test_import_database_row_expansion_enabled(self, mock_add_permissions):
+        """
+        Database API: Test import database with row expansion enabled.
+        """
+        self.login(ADMIN_USERNAME)
+        uri = "api/v1/database/import/"
+
+        masked_database_config = database_config.copy()
+        masked_database_config["extra"]["schema_options"] = {"expand_rows": 
True}
+
+        buf = BytesIO()
+        with ZipFile(buf, "w") as bundle:
+            with bundle.open("database_export/metadata.yaml", "w") as fp:
+                fp.write(yaml.safe_dump(database_metadata_config).encode())
+            with bundle.open(
+                "database_export/databases/imported_database.yaml", "w"
+            ) as fp:
+                fp.write(yaml.safe_dump(masked_database_config).encode())
+        buf.seek(0)
+
+        form_data = {
+            "formData": (buf, "database_export.zip"),
+            "passwords": json.dumps({"databases/imported_database.yaml": 
"SECRET"}),
+        }
+        rv = self.client.post(uri, data=form_data, 
content_type="multipart/form-data")
+        response = json.loads(rv.data.decode("utf-8"))
+
+        assert rv.status_code == 200
+        assert response == {"message": "OK"}
+
+        database = (
+            
db.session.query(Database).filter_by(uuid=database_config["uuid"]).one()
+        )
+        assert database.extra == json.dumps({"schema_options": {"expand_rows": 
True}})
+
+        db.session.delete(database)
+        db.session.commit()
+
     @mock.patch(
         "superset.db_engine_specs.base.BaseEngineSpec.get_function_names",
     )

Reply via email to