fix: handle empty catalog when DB supports them (#29840)

This commit is contained in:
Beto Dealmeida
2024-08-13 10:08:43 -04:00
committed by GitHub
parent 9f5eb899e8
commit 39209c2b40
23 changed files with 100 additions and 148 deletions

View File

@@ -54,23 +54,28 @@ class CreateDatasetCommand(CreateMixin, BaseCommand):
def validate(self) -> None:
exceptions: list[ValidationError] = []
database_id = self._properties["database"]
schema = self._properties.get("schema")
catalog = self._properties.get("catalog")
schema = self._properties.get("schema")
table_name = self._properties["table_name"]
sql = self._properties.get("sql")
owner_ids: Optional[list[int]] = self._properties.get("owners")
table = Table(self._properties["table_name"], schema, catalog)
# Validate uniqueness
if not DatasetDAO.validate_uniqueness(database_id, table):
exceptions.append(DatasetExistsValidationError(table))
# Validate/Populate database
database = DatasetDAO.get_database_by_id(database_id)
if not database:
exceptions.append(DatabaseNotFoundValidationError())
self._properties["database"] = database
# Validate uniqueness
if database:
if not catalog:
catalog = self._properties["catalog"] = database.get_default_catalog()
table = Table(table_name, schema, catalog)
if not DatasetDAO.validate_uniqueness(database, table):
exceptions.append(DatasetExistsValidationError(table))
# Validate table exists on dataset if sql is not provided
# This should be validated when the dataset is physical
if (