aminghadersohi commented on code in PR #43725:
URL: https://github.com/apache/superset/pull/43725#discussion_r4021554670
##########
superset/datasets/api.py:
##########
@@ -1536,17 +1536,30 @@ def get_or_create_dataset(self) -> Response:
# physical Postgres/MySQL table stored with a non-NULL schema).
# If two datasets share the ``table_name`` across schemas and the
# caller omits ``schema``, surface a 400 with an actionable message
- # instead of the original 500 ``MultipleResultsFound``.
+ # instead of the original 500 ``MultipleResultsFound``. The same guard
+ # applies when the caller supplies ``schema`` but two legacy rows still
+ # match with ``catalog=None`` (the composite unique constraint treats
+ # NULL catalogs as distinct), so both branches catch the exception.
# Catalog follows the same literal-pass rule: existing datasets
# created before multi-catalog support landed are stored with
# ``catalog=None``, so applying ``database.get_default_catalog()``
# would miss them.
schema = body.get("schema") or None
catalog = body.get("catalog") or None
if schema:
- table = DatasetDAO.get_table_by_catalog_schema_and_name(
- database_id, schema, table_name, catalog=catalog
- )
+ try:
+ table = DatasetDAO.get_table_by_catalog_schema_and_name(
+ database_id, schema, table_name, catalog=catalog
+ )
+ except MultipleResultsFound:
+ return self.response_400(
+ message=(
+ f"Multiple datasets named '{table_name}' exist in "
+ f"schema '{schema}' of this database with no catalog "
+ "set. These are duplicate legacy rows; contact an "
+ "admin to remove the duplicates."
Review Comment:
Retracting my own round-1 wording — you applied it verbatim, so this one's
mine. `catalog` is inside the `filter_by`, so this branch also fires for a
non-NULL catalog, and upgraded DBs have no UC at all (`16755d4ca4ae` drops the
3-col one; none creates the 4-col). Keeps your test phrase.
```suggestion
f"schema '{schema}' of this database. These are "
"duplicate rows; contact an admin to remove the "
"duplicates."
```
--
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]