fix(sqlite): use correct check for unique/primary key constraint violations

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang 2025-03-19 13:22:25 +05:30
parent 05fca5b16b
commit 9fa330c075
No known key found for this signature in database
GPG key ID: 9DCC61E211BF645F
2 changed files with 5 additions and 5 deletions

View file

@ -78,12 +78,12 @@ class SQLiteExceptionUtil:
return "too many columns" in str(e)
@staticmethod
def is_primary_key_violation(e: sqlite3.Error) -> bool:
return "UNIQUE constraint failed" in str(e)
def is_primary_key_violation(e: sqlite3.IntegrityError) -> bool:
return e.sqlite_errorcode == 1555
@staticmethod
def is_unique_key_violation(e: sqlite3.Error) -> bool:
return "UNIQUE constraint failed" in str(e)
def is_unique_key_violation(e: sqlite3.IntegrityError) -> bool:
return e.sqlite_errorcode == 2067
@staticmethod
def is_interface_error(e: sqlite3.Error):

View file

@ -717,7 +717,7 @@ class BaseDocument:
doc.db_update()
def show_unique_validation_message(self, e):
if frappe.db.db_type != "postgres":
if frappe.db.db_type == "mariadb":
fieldname = str(e).split("'")[-2]
label = None