Herestothegamers commented on code in PR #42603:
URL: https://github.com/apache/superset/pull/42603#discussion_r3725194360


##########
superset/commands/database/uploaders/base.py:
##########
@@ -261,10 +261,28 @@ def validate_file_size(cls, file: Any) -> None:
         if size is not None and size > max_file_size:
             raise DatabaseUploadFileTooLarge()
 
+    @staticmethod
+    def _resolve_default_schema(database: Database) -> Optional[str]:
+        """Resolve the database's default schema so uploaded datasets carry an
+        explicit schema instead of NULL, which would otherwise duplicate an
+        existing dataset over the same table (see #36305)."""
+        try:
+            return database.get_default_schema(database.get_default_catalog())
+        except Exception:  # pylint: disable=broad-except
+            # Resolution opens an inspector connection; a failure here must
+            # degrade to the no-schema behavior rather than fail the upload.
+            logger.warning(
+                "Unable to resolve default schema for upload; proceeding 
without one",
+                exc_info=True,
+            )
+            return None
+
     def validate(self) -> None:
         self._model = DatabaseDAO.find_by_id(self._model_id)
         if not self._model:
             raise DatabaseNotFoundError()
+        if not self._schema:
+            self._schema = self._resolve_default_schema(self._model)

Review Comment:
   Same resolution as the sibling comment — addressed in 4d09913 via the 
`engine_resolved` path: case-insensitive matching for the resolved default 
schema only, exact matching preserved for user-supplied schemas.



##########
superset/databases/schemas.py:
##########
@@ -1455,6 +1455,19 @@ def convert_column_data_types(
                 ) from ex
         return data
 
+    @post_load
+    def normalize_schema(self, data: dict[str, Any], **kwargs: Any) -> 
dict[str, Any]:
+        # Broken clients stringify an unset schema into the multipart body as
+        # "undefined"/"null"; neither is a plausible real schema name, so both
+        # are treated as unset alongside empty/whitespace values (see #36305).
+        if (schema := data.get("schema")) is not None:
+            schema = schema.strip()
+            if not schema or schema.lower() in ("undefined", "null"):
+                data.pop("schema", None)
+            else:

Review Comment:
   Addressed in 4d09913: `normalize_schema` now drops only the exact strings 
`undefined` and `null` — what JS `String()` emits for an unset value, matched 
case-sensitively — plus empty/whitespace-only values. A quoted schema actually 
named `NULL`/`Undefined`, or an identifier with surrounding whitespace, now 
reaches the upload command verbatim (the earlier `.strip()` of non-empty values 
was removed as well). Covered by the updated normalization matrix in 
`api_test.py`.



-- 
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]

Reply via email to