mikebridge commented on code in PR #39977:
URL: https://github.com/apache/superset/pull/39977#discussion_r3284386070


##########
superset/commands/importers/v1/utils.py:
##########
@@ -400,3 +401,51 @@ def get_resource_mappings_batched(
         mapping.update({str(x.uuid): value_func(x) for x in batch})
         offset += batch_size
     return mapping
+
+
+def find_existing_for_import(model_cls: type[Any], uuid: str) -> Any | None:
+    """Look up an existing row by UUID for an import operation,
+    bypassing the soft-delete visibility filter so soft-deleted matches
+    are returned too.
+
+    Side-effect-free: returns the row as-is whether it's live or
+    soft-deleted (or ``None`` if no row exists). The caller is
+    responsible for deciding what to do with a soft-deleted match —
+    typically calling :func:`clear_soft_deleted_for_import` to remove
+    it before re-import, but only after the caller has validated
+    overwrite/permission decisions.
+
+    Splitting the lookup from the destructive cleanup keeps the
+    destructive action explicit at the call site, so a future change
+    that adds a permission check on the overwrite path doesn't
+    silently leave a "duck around it via soft-delete" backdoor.
+    """
+    return (
+        db.session.query(model_cls)
+        .execution_options(**{SKIP_VISIBILITY_FILTER_CLASSES: {model_cls}})
+        .filter_by(uuid=uuid)
+        .first()
+    )
+
+
+def clear_soft_deleted_for_import(existing: Any) -> None:

Review Comment:
   False positive. `clear_soft_deleted_for_import` is always called from inside 
the v1 importer's outer `@transaction()` wrapper (`ImportModelsCommand.run` → 
`import_dashboard`/`import_chart`/`import_dataset` → 
`clear_soft_deleted_for_import`). The transaction decorator detects nesting via 
`getattr(g, "in_transaction", False)` and short-circuits to direct invocation 
when already inside one — so adding the decorator here would be redundant. The 
destructive op is committed (or rolled back) as part of the outer import 
unit-of-work, which is the right scope.



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