From e810fb7eca1d62937ebbed6d5f69d47e237cf81e Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 29 Feb 2024 16:30:24 +0530 Subject: [PATCH] feat: nowait to skip blocking locks --- frappe/database/database.py | 10 ++++++++++ frappe/database/query.py | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frappe/database/database.py b/frappe/database/database.py index 93b157cafe..fc0f5f50cf 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -474,6 +474,7 @@ class Database: pluck=False, distinct=False, skip_locked=False, + wait=True, ): """Return a document property or list of properties. @@ -488,6 +489,7 @@ class Database: :param pluck: pluck first column instead of returning as nested list or dict. :param for_update: All the affected/read rows will be locked. :param skip_locked: Skip selecting currently locked rows. + :param wait: Wait for aquiring lock Example: @@ -519,6 +521,7 @@ class Database: distinct=distinct, limit=1, skip_locked=skip_locked, + wait=wait, ) if not run: @@ -552,6 +555,7 @@ class Database: distinct=False, limit=None, skip_locked=False, + wait=True, ): """Return multiple document properties. @@ -592,6 +596,7 @@ class Database: limit=limit, as_dict=as_dict, skip_locked=skip_locked, + wait=True, for_update=for_update, ) @@ -619,6 +624,7 @@ class Database: limit=limit, for_update=for_update, skip_locked=skip_locked, + wait=wait, ) except Exception as e: if ignore and ( @@ -856,6 +862,7 @@ class Database: update=None, for_update=False, skip_locked=False, + wait=True, run=True, pluck=False, distinct=False, @@ -867,6 +874,7 @@ class Database: order_by=order_by, for_update=for_update, skip_locked=skip_locked, + wait=wait, fields=fields, distinct=distinct, limit=limit, @@ -892,6 +900,7 @@ class Database: as_dict=False, for_update=False, skip_locked=False, + wait=True, ): if names := list(filter(None, names)): return frappe.qb.get_query( @@ -904,6 +913,7 @@ class Database: validate_filters=True, for_update=for_update, skip_locked=skip_locked, + wait=wait, ).run(debug=debug, run=run, as_dict=as_dict, pluck=pluck) return {} diff --git a/frappe/database/query.py b/frappe/database/query.py index c7a7eee240..2a28375428 100644 --- a/frappe/database/query.py +++ b/frappe/database/query.py @@ -48,6 +48,7 @@ class Engine: *, validate_filters: bool = False, skip_locked: bool = False, + wait: bool = True, ) -> QueryBuilder: self.is_mariadb = frappe.db.db_type == "mariadb" self.is_postgres = frappe.db.db_type == "postgres" @@ -84,7 +85,7 @@ class Engine: self.query = self.query.distinct() if for_update: - self.query = self.query.for_update(skip_locked=skip_locked) + self.query = self.query.for_update(skip_locked=skip_locked, nowait=not wait) if group_by: self.query = self.query.groupby(group_by)