Commit graph

84 commits

Author SHA1 Message Date
Sagar Vora
2a36631997 test: add tests for child tables of single doctypes 2025-12-22 12:15:23 +05:30
Sagar Vora
d1ffd99fe8 fix(query): wrap CombinedRawCriterion in parentheses for correct precedence
Without proper grouping, OR conditions from shared docs could bypass WHERE filters:
  WHERE filter=X AND perm_cond OR shared_cond  -- shared_cond ignores filter!

With proper grouping:
  WHERE filter=X AND (perm_cond OR shared_cond)  -- correct behavior
2025-12-17 22:28:52 +05:30
Sagar Vora
591d9a3535 fix: update logic for child tables 2025-12-17 19:03:15 +05:30
Akhil Narang
207ee7a367
fix(query): match between behaviour for datetime fields with db_query
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-12-08 20:06:32 +05:30
Aarol D'Souza
cf69e4bed1
fix(postgres): misc query building fixes + CI (#34831)
* fix(query): check standard field definitions

Signed-off-by: Akhil Narang <me@akhilnarang.dev>

* fix(postgres): fix order_by problem in pg

* fix(postgres): fix order_by in get_all for _test_connection_query

* fix: add check to a proper numeric fallback in _get_ifnull_fallback

* test(postgres): fix pg query used in assertion in test_permission_query

* fix(postgres): fix order_by in get_all for possible_link

* fix(postgres): fix order_by in get_all for set_modules

* fix(postgres): fix pg query count *

* fix(postgres): fix order_by in get_all for ask_pass_update

* fix(postgres): fix order_by statement in search_widget

* fix(postgres): fix order_by in get_list for get_stats

* test(postgres): normalize_sql for pg queries in test_arithmetic_operators_in_fields

* test(postgres): normalize_sql for pg queries in test_field_alias_in_group_by

* test(postgres): normalize_sql for pg queries in test_field_alias_permission_check

* test(postgres): fix order_by statement in get_all for test_db_keywords_as_fields

* test(postgres): fix order_by statement in get_all for test_prepare_select_args

* fix(treeview): use 0 instead of false to check since check field is an integer

* fix(postgres): fix order_by in get_all for sync_communication

* fix(postgres): fix order_by in get_all for get_references_across_doctypes_by_dynamic_link_field

* test(postgres): fix order_by in get_all for test_list_summary

* fix(postgres): fix order_by in get_all for email queries

* test(postgres): use order_by none and update assertion for postgres

* fix(postgres): use ILIKE to support case insensitive search in postgres

* test(test_query): update pg specific query assert to use ILIKE

* test(test_query): update test_nested_filters to use ilike instead for PG

* test(postgres): update pg query in assert to test updated qb query

* fix(search): update query to be db-agnostic

* test(postgres): normalize query for pg in test_build_match_conditions

* fix(postgres): suppress ORDER BY when SELECT DISTINCT in query for postgres specific behavior

* fix(postgres): suppress ORDER BY when GROUP BY is explicitly asked for pg specific behavior

* test(postgres): fix test behavior for pg ORDER BY drop when used with GROUP BY

* refactor: reducing noise in code by formatting code

* fix(query): use Star() to handle SQL wildcard character * correctly

* fix(postgres): display warning for ORDER BY fields that will be dropped

---------

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Co-authored-by: Akhil Narang <me@akhilnarang.dev>
2025-12-05 10:30:49 +05:30
Akhil Narang
ba192648f3
fix(qb): track field aliases
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-11-20 18:05:33 +05:30
Akhil Narang
15588de6cd
fix(query): ensure backwards compatibility for sorting, filtering
If `db_query_compat=True` (set by `qb_query.py`), then we default to some `db_query.py` behaviour.
Otherwise, we'll retail the previous query builder behaviour, this is to minimize breakage on either side.

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-11-19 21:15:58 +05:30
Akhil Narang
2c15bb4a5b
fix(query): extend regex for allow backticked aliases
For example:

```
`tabSerial and Batch Entry`.`name` as `child_row`
```

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-11-19 21:15:58 +05:30
Akhil Narang
943df998d6
feat: support certain backticked expressions
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-11-19 21:15:58 +05:30
Akhil Narang
3040ab7eb2
feat(query): add in IFNULL logic from db_query
Use `IFNULL(var, "") == ""` instead of `isnull()`

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-11-19 21:15:57 +05:30
Akhil Narang
340fe279b3
feat: add in initial version of DatabaseQuery using query builder
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-11-19 21:15:57 +05:30
AarDG10
a12d855147 test(postgres): fix mariadb specific identifiers for postgres queries using normalize_sql 2025-11-11 13:13:51 +05:30
AarDG10
de600a42c8 test(postgres): fix test_dynamic_fields_in_group_by for Postgres 2025-11-04 22:22:14 +05:30
AarDG10
d910dbff19 test(postgres): fix test_multiple_dynamic_fields_group_order for Postgres 2025-11-04 21:17:20 +05:30
AarDG10
af08b40c09 test(postgres): fix test_sql_functions_in_fields for Postgres 2025-11-04 18:48:23 +05:30
AarDG10
4fc7661bfe test(postgres): enable test_string_fields to run on Postgres 2025-11-04 18:17:52 +05:30
AarDG10
cb636f7c5c test(postgres): fix test_filters for Postgres 2025-11-04 17:42:33 +05:30
AarDG10
b4d75132d4 test(postgres): fix test_multiple_tables_in_filters for Postgres 2025-11-04 17:17:38 +05:30
AarDG10
5ec28f99c6 test(postgres): fix test_not_equal_condition_on_none for Postgres 2025-11-04 16:47:54 +05:30
Ejaaz Khan
3f5b192326 test: add test for not equal none condition 2025-09-30 14:55:44 +05:30
Soham Kulkarni
64db88228f
refactor: seperate blogs into a seperate app (#32737)
* fix: remove doctypes,workspace blocks, files

* fix: minor python tests and UI tests

* fix: remove blog post from tests

* fix: remove blogger as role for tests

* fix: add check for if doctype exists

* fix: ui test

* fix: more cleanup

* fix: cleanup comments and fix test_query

* fix: resolve conflicts

* fix: add warning and handle comments
2025-07-28 14:35:02 +05:30
Sagar Vora
8b13971ab2 test: use contextmanager to set user 2025-06-27 14:51:26 +05:30
Faris Ansari
f2a0724f9a feat: add back sql functions support with json syntax
```
fields=['user_type', {'COUNT': 'name', 'as': 'total'}]
fields=[{"IFNULL": ["first_name", "'Unknown'"], "as": "safe_name"}]
```
2025-06-18 16:15:25 +05:30
Faris Ansari
840e7991ce fix: dont allow partial backticks
- add tests
2025-06-18 16:14:32 +05:30
Faris Ansari
3f65806a0b fix: harden group by and order by inputs
- only field, link_field.field, child_field.field allowed
- dont allow backticks
- add permlevel check
- add tests
2025-06-18 16:10:52 +05:30
Faris Ansari
420e891d96 feat: remove support for sql functions in fields 2025-06-18 16:10:52 +05:30
Faris Ansari
9a84f20436 feat: add support for nested AND and OR conditions 2025-06-18 16:10:52 +05:30
Faris Ansari
b2a37f86b3 fix: filtering should only be allowed on permitted fields 2025-06-18 16:00:22 +05:30
Faris Ansari
f77a940582 fix: check permlevel for fields like "link_field.fieldname" 2025-06-18 16:00:22 +05:30
Faris Ansari
63afc0601b fix: restrict child table access if user has only "select" on parent 2025-06-18 16:00:22 +05:30
Faris Ansari
a9fb29fb8e test: test for invalid inputs in fields, filters, group_by, order_by
- comment out invalid tests
2025-06-18 16:00:22 +05:30
Faris Ansari
39a65a1300 test: enable server script temporarily 2025-06-18 15:56:11 +05:30
Faris Ansari
601df8268f test: simpler assertions 2025-06-18 15:56:11 +05:30
Faris Ansari
a94c143314 fix: add support for permission query conditions 2025-06-18 15:56:11 +05:30
Faris Ansari
3ab0e8756f test: mandatory field 2025-06-18 15:56:11 +05:30
Faris Ansari
ccca6bffab test: add permissions tests for qb.get_query 2025-06-18 15:56:11 +05:30
David Arnold
c114e5fae8
refactor: unit vs integration treewide (#27992)
* refactor: constitute unit test case

* fix: docs and type hints

* refactor: mark presumed integration test cases explicitly

At time of writing, we now have at least two base test classes:

- frappe.tests.UnitTestCase
- frappe.tests.IntegrationTestCase

They load in their perspective priority queue during execution.

Probably more to come for more efficient queing and scheduling.

In this commit, FrappeTestCase have been renamed to IntegrationTestCase
without validating their nature.

* feat: Move test-related functions from test_runner.py to tests/utils.py

* refactor: add bare UnitTestCase to all doctype tests

This should teach LLMs in their next pass that the distinction matters
and that this is widely used framework practice
2024-10-06 09:43:36 +00:00
Ankush Menat
071e269548 fix!: Switch to creation as default sort order 2024-03-27 11:18:28 +05:30
Ankush Menat
de9ac89748 style: re-format with ruff 2024-02-05 18:53:33 +05:30
Sagar Vora
81d5160ac1 test: ensure stricter filters when validate_filters is passed 2023-05-31 14:16:52 +05:30
Sagar Vora
9f5a994f70 fix!: improved filter validation in Engine.get_query 2023-05-31 14:16:52 +05:30
Faris Ansari
7e7b1e024a test: for child query in qb.get_query 2023-05-08 18:55:11 +05:30
Faris Ansari
543458b473 fix: handle empty list as filters 2023-01-16 15:38:15 +05:30
Faris Ansari
5bc5ff100b test: tests for various filter options 2023-01-16 14:12:04 +05:30
Faris Ansari
b7c0ba1bea fix: allow dynamic fields in filters
e.g.,
`filters={'link.field': 'value'}`
`filters={'child.field': 'value'}`
2022-12-31 22:55:00 +05:30
Faris Ansari
7ca39a81bf fix: explicitly specifiy order 2022-12-31 22:18:07 +05:30
Faris Ansari
726fcfdb79 refactor: qb.engine
- simplify
- qb.engine.get_query -> qb.get_query
- qb.engine.build_conditions -> qb.get_query
2022-12-25 23:19:11 +05:30
phot0n
dfe62f2614 test: use double quotes for postgres query assertions 2022-11-03 12:50:38 +05:30
Aradhya
e1719fd30c feat: Added support for table_field.fieldname and tests 2022-11-03 03:56:59 +05:30
Aradhya
88d506864b refactor: consistent quries and better naming 2022-11-02 17:21:37 +05:30