fix(query): use default limit when offset is used in MariaDB and SQLite

MariaDB and SQLite don't allow use of offset as a standalone, limit is a must, enforcing that in QB. PostgreSQL allows use of offset w/o limit clause.
This commit is contained in:
AarDG10 2026-04-30 10:17:26 +05:30
parent 73a81e0c02
commit d6adf919c9

View file

@ -172,6 +172,9 @@ BACKTICK_FIELD_PARSE_REGEX = re.compile(r"^`tab([\w\s-]+)`\.(`?)(\w+)\2$")
# Group 3: Fieldname # Group 3: Fieldname
CHILD_TABLE_FIELD_PATTERN = re.compile(r'^[`"]?tab([\w\s]+)[`"]?\.([`"]?)(\w+)\2$') CHILD_TABLE_FIELD_PATTERN = re.compile(r'^[`"]?tab([\w\s]+)[`"]?\.([`"]?)(\w+)\2$')
# Maximum value of an unsigned 64-bit integer
MAX_LIMIT = 18446744073709551615
# Direct mapping from uppercase function names to pypika function classes # Direct mapping from uppercase function names to pypika function classes
FUNCTION_MAPPING = { FUNCTION_MAPPING = {
"COUNT": functions.Count, "COUNT": functions.Count,
@ -299,6 +302,11 @@ class Engine:
if offset: if offset:
if not isinstance(offset, int) or offset < 0: if not isinstance(offset, int) or offset < 0:
frappe.throw(_("Offset must be a non-negative integer"), TypeError) frappe.throw(_("Offset must be a non-negative integer"), TypeError)
# In MariaDB and SQLite, offset requires limit
if not self.is_postgres and not limit:
self.query = self.query.limit(MAX_LIMIT)
self.query = self.query.offset(offset) self.query = self.query.offset(offset)
if distinct: if distinct: