sadpandajoe commented on code in PR #40123:
URL: https://github.com/apache/superset/pull/40123#discussion_r3243144152
##########
tests/unit_tests/datasets/commands/export_test.py:
##########
@@ -304,3 +304,54 @@ def test_export(session: Session) -> None:
""",
),
]
+
+
+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}
Review Comment:
Could we have used yaml.safe_load here instead of trying to split it this
way? But probably not urgent enough to be blocking.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]