From 0d07c3165bb4709761638dbe3f62892d309b27f2 Mon Sep 17 00:00:00 2001 From: Dimitri Yatsenko Date: Thu, 8 Jan 2026 22:57:18 -0600 Subject: [PATCH] fix: translate MySQL error 3730 to IntegrityError (#1032) When dropping a table/schema referenced by foreign key constraints, MySQL returns error 3730. This was passing through as a raw pymysql OperationalError, making it difficult for users to catch and handle. Now translates to datajoint.errors.IntegrityError, consistent with other foreign key constraint errors (1217, 1451, 1452). Before: pymysql.err.OperationalError: (3730, "Cannot drop table...") After: datajoint.errors.IntegrityError: Cannot drop table '#table' referenced by a foreign key constraint... Fixes #1032 Co-Authored-By: Claude Opus 4.5 --- src/datajoint/connection.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/datajoint/connection.py b/src/datajoint/connection.py index 394952886..0736eba11 100644 --- a/src/datajoint/connection.py +++ b/src/datajoint/connection.py @@ -66,7 +66,11 @@ def translate_query_error(client_error: Exception, query: str) -> Exception: # Integrity errors case 1062: return errors.DuplicateError(*args) - case 1217 | 1451 | 1452: + case 1217 | 1451 | 1452 | 3730: + # 1217: Cannot delete parent row (FK constraint) + # 1451: Cannot delete/update parent row (FK constraint) + # 1452: Cannot add/update child row (FK constraint) + # 3730: Cannot drop table referenced by FK constraint return errors.IntegrityError(*args) # Syntax errors