Commit graph

100 commits

Author SHA1 Message Date
AarDG10
2ea2c68e6e test: fix tests to accomodate new change 2026-04-28 19:46:11 +05:30
Sagar Vora
2a2350d3a4 test: ensure fields with accented chars are considered valid 2026-03-26 17:25:51 +05:30
Sagar Vora
7a113c0aee
fix: use correct core doctypes set in _get_filterable_fields (#37932) 2026-03-11 17:19:48 +05:30
Suraj Shetty
0c211aa4a0
Merge pull request #35940 from AarDG10/fix-orderby-pg 2026-02-22 13:09:43 +05:30
Sagar Vora
95283be9f5
Merge pull request #37316 from sagarvora/fix/select-permission-filter-fields
fix: allow filtering by all permlevel 0 fields with select permission
2026-02-20 21:34:06 +05:30
Sagar Vora
369f15ac09 fix: allow filtering by all permlevel 0 fields with select permission
Users with only 'select' permission can now filter, order by, and
group by all permlevel 0 fields, not just search fields.

- Added _get_filterable_fields() returning all permlevel 0 fields
  for select permission users
- Split permission checking into check_select_field_permission()
  and check_filter_field_permission()
- select field validation uses check_select_field_permission
- Filter/order/group by validation uses check_filter_field_permission
2026-02-20 21:23:29 +05:30
Shllokkk
16e6c40d70
fix(schema): drop unique constraint for deleted doctype fields (#36356)
* fix(schema): drop unique constraint and indexes for deleted doctype fields

* refactor(schema): rename a variable and remove commented code

* test: add test case for dropping unique constraint on field deletion from doctype

* fix(tests): prevent list mutation during iteration

* test(db): guard MariaDB-specific unique index test with db_type_is.MARIADB

* fix(schema): drop unique constraints and indexes for deleted fields on postgres

* fix(schema): make postgres unique cleanup idempotent for deleted fields

* fix(schema): make postgres unique cleanup idempotent on reload

* test: add test case for dropping unique constraint and index on field deletion for postgres

* fix(schema): make postgres unique cleanup idempotent
2026-02-20 20:15:32 +05:30
Sumit Jain
c6868b11c6 feat: Enhance IN/NOT IN operator handling for empty lists
Added logic to return appropriate criteria for empty lists in IN and NOT IN operators. An empty list with IN now returns 0 results (1=0), while NOT IN returns all results (1=1). Updated tests to verify this behavior.
2026-02-03 12:31:29 +05:30
Aarol D'Souza
95450c85bd chore: resolve conflicts 2026-01-27 19:57:50 +05:30
AarDG10
4301d9dff2 test: add coverage for ifnull fallback in postgres 2026-01-22 10:11:29 +05:30
AarDG10
620d5def7b test: add coverage for variations in query_building 2026-01-16 13:11:57 +05:30
AarDG10
4530996223 revert(validation): revert validation due to breakage in old queries 2026-01-15 22:35:39 +05:30
AarDG10
4530014ee5 test: add test for postgres query validation feat 2026-01-15 18:14:26 +05:30
AarDG10
96520edf5a test: add coverage for aggregate fields selected but not grouped 2026-01-14 20:07:31 +05:30
AarDG10
157a657c1f test: add tests for order_by group_by behavior in postgres 2026-01-14 18:19:35 +05:30
Aarol D'Souza
59b440cb28
fix(search): make QB DB-Aware when using Locate (#35796)
* fix: make QB DB-Aware when choosing Locate

* fix(test): adjust test to check smarter qb choice based on db
2026-01-12 12:06:28 +05:30
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