From a14b11749b0c7ad1220d08808df68baee33c2b87 Mon Sep 17 00:00:00 2001 From: Sagar Vora <16315650+sagarvora@users.noreply.github.com> Date: Tue, 2 Dec 2025 00:40:23 +0530 Subject: [PATCH] refactor: remove unnecessary sql_keywords validation in _validate_alias pypika wraps aliases in backticks, so SQL keywords are safe to use as aliases --- frappe/database/query.py | 67 +--------------------------------------- 1 file changed, 1 insertion(+), 66 deletions(-) diff --git a/frappe/database/query.py b/frappe/database/query.py index 5cf2715734..a18ccadea8 100644 --- a/frappe/database/query.py +++ b/frappe/database/query.py @@ -2073,78 +2073,13 @@ class SQLFunctionParser: frappe.throw(_("Empty alias is not allowed"), frappe.ValidationError) # Alias should be a simple identifier + # Note: pypika wraps aliases in backticks, so anything without backticks is safe if not IDENTIFIER_PATTERN.match(alias): frappe.throw( _("Invalid alias format: {0}. Alias must be a simple identifier.").format(alias), frappe.ValidationError, ) - # Check for SQL keywords that shouldn't be used as aliases - sql_keywords = { - "select", - "from", - "where", - "join", - "inner", - "left", - "right", - "outer", - "union", - "group", - "order", - "by", - "having", - "limit", - "offset", - "insert", - "update", - "delete", - "create", - "drop", - "alter", - "table", - "index", - "view", - "database", - "schema", - "grant", - "revoke", - "commit", - "rollback", - "transaction", - "begin", - "end", - "if", - "else", - "case", - "when", - "then", - "null", - "not", - "and", - "or", - "in", - "exists", - "between", - "like", - "is", - "as", - "on", - "using", - "distinct", - "all", - "any", - "some", - "true", - "false", - } - - if alias.lower() in sql_keywords: - frappe.throw( - _("Alias cannot be a SQL keyword: {0}").format(alias), - frappe.ValidationError, - ) - def _validate_function_field_arg(self, field_name: str): """Validate a field name used as a function argument.""" if not isinstance(field_name, str):