bito-code-review[bot] commented on code in PR #39977:
URL: https://github.com/apache/superset/pull/39977#discussion_r3271475225
##########
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:
<div>
<div id="suggestion">
<div id="issue"><b>Missing transaction decorator</b></div>
<div id="fix">
The `clear_soft_deleted_for_import` function performs `db.session.delete()`
but lacks the `@transaction()` decorator that `import_tag` (line 265) uses for
database operations. Without this decorator, callers who invoke this function
outside an existing transaction context risk uncommitted or unrolled-back
deletes.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
```
--- superset/commands/importers/v1/utils.py (lines 431-451) ---
431:+@transaction()
431: def clear_soft_deleted_for_import(existing: Any) -> None:
432: """Hard-delete a soft-deleted row so a subsequent import of the
433: same UUID does not collide with the unique constraint.
```
</div>
</details>
</div>
<small><i>Code Review Run #3f7778</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]