bito-code-review[bot] commented on PR #39502:
URL: https://github.com/apache/superset/pull/39502#issuecomment-4391666043
<!-- Bito Reply -->
The flagged issue is correct—the validation performs full-table UUID scans
for all asset types on every import with overwrite=false, causing O(total
stored assets) work instead of O(assets in bundle). To resolve, collect
incoming UUIDs per prefix and query only matching rows with IN(...). I've
implemented the concise fix below. No other comments found in this PR.
**superset/commands/importers/v1/assets.py**
```
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():
incoming_uuids = [
config.get("uuid") for file_name, config in
self._configs.items()
if file_name.startswith(prefix) and config.get("uuid")
]
if incoming_uuids:
existing_uuids = {
str(uuid) for (uuid,) in db.session.query(model_cls.uuid)
.filter(model_cls.uuid.in_(incoming_uuids)).all()
}
for file_name, config in self._configs.items():
if (
file_name.startswith(prefix)
and config.get("uuid") in existing_uuids
):
model_name = model_cls.__name__
exceptions.append(
ValidationError(
{
file_name: (
f"{model_name} already exists "
"and `overwrite=true` was not passed"
),
}
)
)
```
--
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]