codeant-ai-for-open-source[bot] commented on code in PR #44184:
URL: https://github.com/apache/superset/pull/44184#discussion_r4033279490


##########
superset/commands/dashboard/create.py:
##########
@@ -44,6 +49,17 @@ def __init__(self, data: dict[str, Any]) -> None:
     def run(self) -> Model:
         self.validate()
         dashboard = DashboardDAO.create(attributes=self._properties)
+        # Surface the INSERT here rather than at the transaction decorator's
+        # commit, so a slug collision with a SOFT-DELETED dashboard (possible
+        # only on the full-constraint dialects; the partial-index dialects
+        # free the slot) can be translated into restore guidance. Any other
+        # integrity failure re-raises unchanged.
+        try:
+            db.session.flush()
+        except IntegrityError as ex:
+            db.session.rollback()  # pylint: disable=consider-using-transaction
+            
raise_for_soft_deleted_slug_collision(self._properties.get("slug"), ex)

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > In this dashboard creation command, retain the explicit session rollback 
after a failed flush so the session can be reused for slug-diagnostic queries; 
do not flag it as losing unrelated outer changes, since the failed flush 
already invalidates the shared transaction.
   
   **Applied to:**
     - `superset/commands/dashboard/create.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
superset/commands/dashboard/update.py:
##########
@@ -112,6 +116,15 @@ def run(self) -> Model:
                 self._model,
                 {k: v for k, v in self._properties.items() if k != 
"json_metadata"},
             )
+            # See CreateDashboardCommand.run: translate a slug collision
+            # with a soft-deleted dashboard (full-constraint dialects) into
+            # restore guidance; anything else re-raises unchanged.
+            try:
+                db.session.flush()
+            except IntegrityError as ex:
+                db.session.rollback()  # pylint: 
disable=consider-using-transaction
+                
raise_for_soft_deleted_slug_collision(self._properties.get("slug"), ex)

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag the explicit rollback after a failed flush in this command; it 
is required to reset the session for diagnostic queries, and failures are 
propagated rather than used for partial-success recovery.
   
   **Applied to:**
     - `superset/commands/dashboard/update.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



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