eschutho commented on code in PR #33070:
URL: https://github.com/apache/superset/pull/33070#discussion_r2036289192


##########
superset/migrations/migration_utils.py:
##########
@@ -15,21 +15,32 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import logging
+
 from alembic.operations import Operations
 
 naming_convention = {
     "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
     "uq": "uq_%(table_name)s_%(column_0_name)s",
 }
 
+logger = logging.getLogger(__name__)
+
 
 def create_unique_constraint(
     op: Operations, index_id: str, table_name: str, uix_columns: list[str]
 ) -> None:
-    with op.batch_alter_table(
-        table_name, naming_convention=naming_convention
-    ) as batch_op:
-        batch_op.create_unique_constraint(index_id, uix_columns)
+    # Run the DDL command in an autocommit block so a failure here
+    # won't abort the outer transaction.
+    try:
+        with op.get_context().autocommit_block():
+            with op.batch_alter_table(
+                table_name, naming_convention=naming_convention
+            ) as batch_op:
+                batch_op.create_unique_constraint(index_id, uix_columns)
+    except Exception as e:
+        # Likely the constraint already exists, or another DDL error occurred.
+        logger.warning("Failed to create unique constraint %s: %s", index_id, 
e)

Review Comment:
   this was failing during testing due to a constraint that already existing 
when downgrading. 



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