fix(qb): support reportview alias format

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang 2026-01-06 19:30:14 +05:30
parent d03130c7db
commit d02d89436e
No known key found for this signature in database
GPG key ID: 9DCC61E211BF645F
2 changed files with 19 additions and 3 deletions

View file

@ -155,8 +155,10 @@ FUNCTION_CALL_PATTERN = re.compile(r"^\s*[a-zA-Z_][a-zA-Z0-9_]*\s*\(", flags=re.
# - `tabTable Name`.`field` (spaces in table name)
# - `tabTable-Field`.`field` (hyphens in table name)
# - Any of above with aliases: ... as alias
# - Single-quoted aliases with colons (used by reportview child fields):
# - ... as 'Child:field'
ALLOWED_FIELD_PATTERN = re.compile(
r"^(?:(`[\w\s-]+`|\w+)\.)?(`\w+`|\w+)(?:\s+as\s+(?:`[\w\s-]+`|\w+))?$",
r"^(?:(`[\w\s-]+`|\w+)\.)?(`\w+`|\w+)(?:\s+as\s+(?:`[\w\s-]+`|'[\w\s:-]+'|\w+))?$",
flags=re.ASCII | re.IGNORECASE,
)
@ -963,7 +965,7 @@ class Engine:
parts = re.split(r"\s+as\s+", field, flags=re.IGNORECASE)
if len(parts) > 1:
field_part = parts[0].strip()
alias = parts[1].strip().strip('`"') # Remove potential quotes from alias
alias = parts[1].strip().strip("`\"'") # Remove potential quotes from alias
match = FIELD_PARSE_REGEX.match(field_part)
@ -1707,7 +1709,7 @@ class DynamicTableField:
parts = re.split(r"\s+as\s+", field, flags=re.IGNORECASE)
if len(parts) > 1:
field_part = parts[0].strip()
alias = parts[-1].strip().strip('`"') # Get last part as alias
alias = parts[-1].strip().strip("`\"'") # Get last part as alias
field = field_part # Use the part before alias for further parsing
child_match = None

View file

@ -1298,6 +1298,20 @@ class TestReportView(IntegrationTestCase):
user.remove_roles("Blogger", "Website Manager")
user.add_roles(*user_roles)
def test_reportview_child_table_alias(self):
from frappe.desk import reportview
frappe.local.form_dict = frappe._dict(
{
"doctype": "DocType",
"fields": ["name", "`tabDocField`.`fieldname` as 'DocField:fieldname'"],
"limit": 1,
}
)
response = reportview.get()
self.assertIn("DocField:fieldname", response["keys"])
self.assertNotIn("'DocField:fieldname'", response["keys"])
def test_reportview_get_aggregation(self):
# test aggregation based on child table field
frappe.local.request = frappe._dict()