revert(validation): revert validation due to breakage in old queries

This commit is contained in:
AarDG10 2026-01-15 22:32:18 +05:30
parent c35f271144
commit 4530996223
2 changed files with 0 additions and 40 deletions

View file

@ -345,8 +345,6 @@ class Engine:
self.query._fields_list = getattr(self, "fields", [])
self.query.immutable = True
if self.is_postgres and self.is_aggregate_query:
self._validate_select_field_grouping_postgres() # DX: validate query
return self.query
def validate_doctype(self):
@ -1743,29 +1741,6 @@ class Engine:
return True
def _validate_select_field_grouping_postgres(self):
"""DX: In PostgreSQL, selected fields used with group by need to either be aggregated or be grouped,
the Query Builder validates this rule if user is unaware"""
# string processing needed since this may break in certain queries e.g."tabDocType"."module"
clean_groups = {
str(g).replace('"', "").replace("`", "").split(".")[-1] for g in self._grouped_queries
}
for field in self.fields:
if isinstance(field, AggregateFunction):
continue
alias = getattr(field, "alias", None)
field_alias = alias.replace('"', "").replace("`", "") if alias else None
field_source = str(field).replace('"', "").replace("`", "").split(".")[-1]
is_grouped = (field_source in clean_groups) or (field_alias in clean_groups)
if not is_grouped:
frappe.throw(
_(
"PostgreSQL grouping error: The field '{0}' is selected but neither grouped nor aggregated. "
"Add it to 'group_by' or aggregate it."
).format(field_alias or field_source),
frappe.ValidationError,
)
class DynamicTableField:
def __init__(

View file

@ -2361,21 +2361,6 @@ class TestQuery(IntegrationTestCase):
self.assertQueryEqual(query, 'SELECT COUNT(*) "result" FROM "tabUser" ORDER BY MAX("creation") DESC')
@run_only_if(db_type_is.POSTGRES)
def test_query_validation_postgres(self):
"""PostgreSQL specific test that tests if query that is built is valid in PostgreSQL, as part of a better DX"""
with self.assertRaises(frappe.ValidationError) as pgerr:
frappe.qb.get_query(
"User",
fields=["user_type as type", "enabled as status", {"COUNT": "*"}],
group_by="type",
order_by="type",
).run()
self.assertEqual(
str(pgerr.exception),
"PostgreSQL grouping error: The field 'status' is selected but neither grouped nor aggregated. Add it to 'group_by' or aggregate it.",
)
# This function is used as a permission query condition hook
def test_permission_hook_condition(user):