From 9fa330c0756fadcb797f176f9bd24f76a038dddd Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Wed, 19 Mar 2025 13:22:25 +0530 Subject: [PATCH] fix(sqlite): use correct check for unique/primary key constraint violations Signed-off-by: Akhil Narang --- frappe/database/sqlite/database.py | 8 ++++---- frappe/model/base_document.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frappe/database/sqlite/database.py b/frappe/database/sqlite/database.py index 2e5f98774f..00537cba35 100644 --- a/frappe/database/sqlite/database.py +++ b/frappe/database/sqlite/database.py @@ -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): diff --git a/frappe/model/base_document.py b/frappe/model/base_document.py index 960e7cb382..bfd8c9271c 100644 --- a/frappe/model/base_document.py +++ b/frappe/model/base_document.py @@ -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