Skip to content

Commit 1673be8

Browse files
fix: translate MySQL error 3730 to IntegrityError (#1032) (#1319)
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 <[email protected]>
1 parent d38a670 commit 1673be8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/datajoint/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ def translate_query_error(client_error: Exception, query: str) -> Exception:
6666
# Integrity errors
6767
case 1062:
6868
return errors.DuplicateError(*args)
69-
case 1217 | 1451 | 1452:
69+
case 1217 | 1451 | 1452 | 3730:
70+
# 1217: Cannot delete parent row (FK constraint)
71+
# 1451: Cannot delete/update parent row (FK constraint)
72+
# 1452: Cannot add/update child row (FK constraint)
73+
# 3730: Cannot drop table referenced by FK constraint
7074
return errors.IntegrityError(*args)
7175

7276
# Syntax errors

0 commit comments

Comments
 (0)