korbit-ai[bot] commented on code in PR #33384:
URL: https://github.com/apache/superset/pull/33384#discussion_r2078815620
##########
superset/commands/dataset/update.py:
##########
@@ -128,15 +106,68 @@ def validate(self) -> None:
except ValidationError as ex:
exceptions.append(ex)
+ self._validate_dataset_source(exceptions)
self._validate_semantics(exceptions)
if exceptions:
raise DatasetInvalidError(exceptions=exceptions)
- def _validate_semantics(self, exceptions: list[ValidationError]) -> None:
+ def _validate_dataset_source(self, exceptions: list[ValidationError]) ->
None:
# we know we have a valid model
self._model = cast(SqlaTable, self._model)
+ database_id = self._properties.pop("database_id", None)
+ catalog = self._properties.get("catalog")
+ new_db_connection: Database | None = None
+
+ if database_id and database_id != self._model.database.id:
+ if new_db_connection := DatasetDAO.get_database_by_id(database_id):
+ self._properties["database"] = new_db_connection
+ else:
+ exceptions.append(DatabaseNotFoundValidationError())
+ db = new_db_connection or self._model.database
+ default_catalog = db.get_default_catalog()
+
+ # If multi-catalog is disabled, and catalog provided is not
+ # the default one, fail
+ if (
+ "catalog" in self._properties
+ and catalog != default_catalog
+ and not db.allow_multi_catalog
+ ):
+ exceptions.append(MultiCatalogDisabledValidationError())
+
+ # If the DB connection does not support multi-catalog,
+ # use the default catalog
+ elif not db.allow_multi_catalog:
+ catalog = self._properties["catalog"] = default_catalog
+
+ # Fallback to using the previous value if not provided
+ elif "catalog" not in self._properties:
+ catalog = self._model.catalog
Review Comment:
I see, makes sense. The local catalog variable is sufficient for validation
and storing it in properties would be redundant. Thanks for clarifying.
--
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]