From 4530014ee5014cdba2c7d5446c3536efcb53cf88 Mon Sep 17 00:00:00 2001 From: AarDG10 Date: Thu, 15 Jan 2026 18:14:26 +0530 Subject: [PATCH] test: add test for postgres query validation feat --- frappe/tests/test_query.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frappe/tests/test_query.py b/frappe/tests/test_query.py index 2962918316..5a73d7a310 100644 --- a/frappe/tests/test_query.py +++ b/frappe/tests/test_query.py @@ -2361,6 +2361,21 @@ 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):