You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/05/14 16:39:41 UTC
(superset) 01/01: test(datasets): regression coverage for #16141 (export with same table name, different schemas)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch test/16141-dataset-export-same-name-schema
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 233eb49bb27f392496db327015530bdeb1af1dbf
Author: Superset Dev <de...@superset.apache.org>
AuthorDate: Thu May 14 09:39:05 2026 -0700
test(datasets): regression coverage for #16141 (export with same table name, different schemas)
Issue #16141 (Aug 2021) reported that the dataset export API returned
only one file when exporting two datasets that shared a table name but
lived in different schemas (e.g. prod.users + dev.users). The current
ExportDatasetsCommand disambiguates the export filename with the
dataset id (`<table_name>_<id>.yaml`), so the collision should no
longer occur — but no test pinned the behavior.
This is a TDD-first PR: the test asserts the *fixed* behavior. If CI
green, the bug is provably gone and #16141 can be closed; if CI red,
the test documents exactly what still needs to be fixed for whoever
picks up the work.
Closes #16141
Co-Authored-By: Claude Opus 4.7 <no...@anthropic.com>
---
tests/unit_tests/datasets/commands/export_test.py | 51 +++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/tests/unit_tests/datasets/commands/export_test.py b/tests/unit_tests/datasets/commands/export_test.py
index a449b764084..df02e0d29b5 100644
--- a/tests/unit_tests/datasets/commands/export_test.py
+++ b/tests/unit_tests/datasets/commands/export_test.py
@@ -304,3 +304,54 @@ version: 1.0.0
""",
),
]
+
+
+def test_export_two_datasets_same_table_name_different_schema(
+ session: Session,
+) -> None:
+ """
+ Regression coverage for GitHub issue #16141.
+
+ Exporting two datasets that share a `table_name` but live in
+ different schemas (e.g. prod.users + dev.users) must produce two
+ distinct entries in the export. Historically the pair could collide
+ onto a single filename — the export filename is now disambiguated by
+ dataset id, so this test pins that behavior so it can't silently
+ regress.
+ """
+ from superset.commands.dataset.export import ExportDatasetsCommand
+ from superset.connectors.sqla.models import SqlaTable
+ from superset.models.core import Database
+
+ engine = db.session.get_bind()
+ SqlaTable.metadata.create_all(engine) # pylint: disable=no-member
+
+ database = Database(database_name="my_database", sqlalchemy_uri="sqlite://")
+ db.session.add(database)
+ db.session.flush()
+
+ prod = SqlaTable(table_name="users", schema="prod", database=database)
+ dev = SqlaTable(table_name="users", schema="dev", database=database)
+ db.session.add_all([prod, dev])
+ db.session.flush()
+
+ paths: list[str] = []
+ contents: list[str] = []
+ for ds in (prod, dev):
+ for path, content_fn in ExportDatasetsCommand._export( # pylint: disable=protected-access
+ ds, export_related=False
+ ):
+ paths.append(path)
+ contents.append(content_fn())
+
+ # Both datasets must produce distinct export paths — no collision.
+ assert len(paths) == len(set(paths)), (
+ f"Export filenames collided for same-table-name datasets: {paths}"
+ )
+
+ # And both YAML payloads must reflect their own schema, not be
+ # silently merged or overwritten.
+ schemas_in_yaml = {c.split("schema:")[1].splitlines()[0].strip() for c in contents}
+ assert schemas_in_yaml == {"prod", "dev"}, (
+ f"Expected both prod and dev schemas in export, got {schemas_in_yaml}"
+ )