mistercrunch commented on code in PR #39502:
URL: https://github.com/apache/superset/pull/39502#discussion_r3203496267
##########
superset/commands/importers/v1/assets.py:
##########
@@ -206,7 +211,48 @@ def _import( # noqa: C901
)
def run(self) -> None:
self.validate()
- self._import(self._configs, self.sparse, self.contents)
+ self._import(self._configs, self.sparse, self.contents, self.overwrite)
+
+ # Maps asset file prefixes to the model class used to look up UUIDs for
+ # the "already exists" validation check when ``overwrite`` is ``False``.
+ _MODEL_BY_PREFIX: dict[str, Any] = {
+ "databases/": Database,
+ "datasets/": SqlaTable,
+ "charts/": Slice,
+ "dashboards/": Dashboard,
+ "queries/": SavedQuery,
+ }
+
+ def _prevent_overwrite_existing_assets(
+ self, exceptions: list[ValidationError]
+ ) -> None:
+ """
+ When ``overwrite`` is ``False``, raise a clear validation error for any
+ asset in the bundle whose UUID already exists in the database.
+ """
+ if self.overwrite:
+ return
+
+ for prefix, model_cls in self._MODEL_BY_PREFIX.items():
+ existing_uuids = {
+ str(uuid) for (uuid,) in db.session.query(model_cls.uuid).all()
+ }
Review Comment:
Good catch — fixed in 38d6293. The validation now groups the bundle's
`(file_name, uuid)` pairs by prefix in one pass over `self._configs`, and only
issues one `WHERE uuid IN (...)` query per prefix that has entries. Prefixes
with nothing in the bundle skip the database entirely, so cost scales with
bundle size instead of the size of each asset table. Added
`test_prevent_overwrite_queries_only_bundle_uuids` to lock in the behavior
(asserts only the relevant model is queried for a single-prefix bundle).
--
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]