Commit graph

165 commits

Author SHA1 Message Date
Prathamesh Kurunkar
69e655d08b
fix(db): support list of fields in get_value method when cache is True (#37050)
* fix(db): support list of fields in get_value method when cache is True

* test(db): ensure cache hit does not execute db query
2026-02-16 20:28:38 +05:30
Aarol D'Souza
77af2d53d6
fix(system console): allow read-only queries in system console (#36652)
* fix(system console): allow read-only queries in system console

* fix(security): make transactions strictly read only for console and scripts

* test: remove test to reflect ban on cte's for security

* fix: Only enable read only mode for SQL query

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
2026-02-05 11:39:10 +00:00
Aarol D'Souza
48c8ee9a78
feat(postgres): add unbuffered cursor in postgres (#35016)
* feat(postgres): add unbuffered cursor in postgres

* test: add unbuffered_cursor test for Postgres
2025-12-23 17:21:28 +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
Aarol D'Souza
a7d8495d7b
test: skip DB-specific tests using new unimplemented_for decorator (#34749)
* test: skip DB-specific tests using new unimplemented_for decorator

* test: use unimplemented to skip tests with implementation problems

* test: update unimplemented to consider multi-DBs

* test: skip test_unbuffered_cursor using unimplemented for pg and sqlite

* test: update unimplemented wrapper
2025-11-28 06:51:45 +00:00
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
30d6ebc6c6
fix: tests
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-11-19 21:15:58 +05:30
Akhil Narang
08e7a72ba2
refactor: uppercase function assertions
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-11-19 21:15:58 +05:30
Akhil Narang
90ed0502fa
refactor: support new function style
- Migrate all SQL function usage from string format to dict format
- Old: fields=['count(*) as count']
- New: fields=[{'COUNT': '*', 'as': 'count'}]
- Add `NULLIF`

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-11-19 21:15:57 +05:30
AarDG10
420c1e7994 test(postgres): update test_is for postgres 2025-11-05 16:52:29 +05:30
Ankush Menat
598ba6d63d
fix: Clear DB value cache after commit/rollback (#34335)
Respect repeatable read, but not beyond transaction, if transaction is committed during a request then cache should be invalidated.

This will likely slow down some code in a loop that did repeated queries + commit but we can't compromise correctness here.
2025-10-10 07:42:11 +00:00
Ankush Menat
1ed2447f6b
fix!: Always cast db.get_value for singles (#33276) 2025-07-11 07:32:41 +00:00
Faris Ansari
e6c939c606 fix: revert get_all change
get_all doesn't use get_query
2025-06-18 16:15:25 +05:30
Faris Ansari
ae3f216255 chore: update sql function usage 2025-06-18 16:15:25 +05:30
Faris Ansari
b2e081d076 chore: update sql function usage 2025-06-18 16:15:25 +05:30
Sagar Vora
b2cab51849
feat: re-introduce mysqlclient 🚀 (#31719)
* feat: mysqlclient

* fix: update error attrs

* fix: decode mogrified query to unicode

* fix: do some cleanup

* chore: disable cleanup for now

* fix: remove unnecessary call to as_unicode

* test: skip perf test for now

* fix: fallback to empty str

* fix: unbuffered cursor support

* fix: update converters and other changes

* fix: add cleanup back

* perf: improve timedelta converter

* fix: dont attempt to run query when explain flag is set

* test: cleanup tests

* chore: remove commented code

* perf: store conf as local var

* chore: ensure sequence

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
2025-03-15 09:48:21 +05:30
Ankush Menat
4406116f86 feat: estimate table size 2025-02-03 09:21:56 +05:30
Ankush Menat
fdba41c682
perf: misc client cache improvements (#29070)
* perf: Reduce penalty for lack of redis connection

If redis isn't running than this client cache is slower than default
implementation because of the extra locking overhead.

* test: update perf redis counts

* perf: cache table columns in client-cache

* fix: race condition on cache-client_cache init

Rare but apparant in synthetic benchmarks.

Cache is set but client cache is still being initialized then request
will fail.

* perf: Don't run notifications when loading document

WHAT?

* fix: use cached doc to repopulate

* perf: reduce get_meta calls
2025-01-07 16:14:43 +05:30
Smit Vora
6b02484f1c
feat: bulk update docs using case when queries (#28483) 2024-12-06 11:34:25 +00:00
David Arnold
9f980e7475
test: add missing test case for get values on single (#28254) 2024-10-23 10:47:46 +02:00
Akhil Narang
e96ff7e65e
Merge pull request #28015 from marination/not-set-filter
fix: 'not set' equivalence in query conditions
2024-10-14 16:00:55 +05:30
David Arnold
e7776021aa
refactor: Structure frappe.test.utils (green to green) (#28038)
* docs: constitute frappe.test readme

* refactor: move utils to __init__

* refactor: move generators into generators.py

* refactor: move cm into context_managers.py

* refactor: move test classes into submodule

* refactor: reexport general purpose context managers

* refactor: adapt imports (treewide)
2024-10-08 15:10:24 +00:00
marination
42e7b9223f fix(test): test_is to check for coalesce as ifnull is legacy for a not set/set filter 2024-10-08 12:31:25 +02:00
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
gruener
8a2aa92389
fix: Fixes mariadb orm to return list instead of tuple as the typisat… (#27179)
* fix: Fixes mariadb orm to return list instead of tuple as the typisation suggests it

* fix: inverted fix for pg: Expect tuple as data_type for _transform_result

* fix: Fixed failing upstream spec due to data_type change
2024-08-09 09:27:07 +05:30
Philipp Gruener
ffcd6d1ff5 fix: Added missing newlines after merge (for pre-commit checks) 2024-07-16 22:52:31 +02:00
gruener
efc9bdd4f6
Merge branch 'develop' into bugfix/postgres_schema_support 2024-07-16 22:47:01 +02:00
Philipp Gruener
7df4185f87 fix: removed TODO marks 2024-07-08 15:16:51 +02:00
Philipp Gruener
c19e844516 fix: Re-establish orig connection in tearDown for failing cases, that following specs dont rely on broken connection 2024-07-05 16:43:15 +02:00
Philipp Gruener
ea3d1365fe fix: Adjusted the retrieved dbms errors to also handle mariadb errors correctly in specs. 2024-07-05 16:26:51 +02:00
Philipp Gruener
1b56b4f3f7 fix: Reset to orig env vars in specs 2024-07-05 15:44:04 +02:00
Philipp Gruener
abba28be3b feat: Added env db options for db, password and pg_schema 2024-07-05 12:05:20 +02:00
Philipp Gruener
d3591c7170 fix: Added missing ruff adjustments 2024-07-04 23:13:14 +02:00
Philipp Gruener
afd95691e9 fix: Fixed schema isolation/support for postgres connectivity. 2024-07-04 22:40:47 +02:00
Philipp Gruener
442ad03d7b feat: Adds possibility of permitting DB credentials via ENV vars instead of persisting them on the volume. 2024-07-04 22:24:21 +02:00
Ankush Menat
5de5e25df6
fix: datetime comparison in QB (#26364)
closes https://github.com/frappe/frappe/issues/26363
2024-05-09 10:19:27 +00:00
Ankush Menat
de48dc2c04
fix: db explain (#25724)
This broke from some recent changes.

It's just a wrapper, so probably no one uses it.
Anyway, fixed and added test to prevent it.
2024-03-29 10:23:12 +00:00
Ankush Menat
23204c0c05
Merge pull request #25256 from ankush/no_commit_doc_events
fix: disable transaction commits during doc events
2024-03-28 12:28:12 +05:30
Ankush Menat
e5a64fd50c test: transaction control 2024-03-28 11:58:38 +05:30
Ankush Menat
b7bc5d3236
fix(round 3): switch to creation sorting (#25669) 2024-03-27 08:59:04 +00:00
Ankush Menat
0fff2755d6
test: separate out risky tests (#25179) 2024-02-29 16:10:08 +00:00
Ankush Menat
0c9cc2e6ce test: NOWAIT functionality 2024-02-29 17:46:30 +05:30
Ankush Menat
5116768a54 test: utils for simulating two connections 2024-02-29 17:31:46 +05:30
Akhil Narang
3f1e19de85
refactor(treewide): enable RUF rules
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-02-21 16:20:28 +05:30
Raffael Meyer
68eb2d978d
fix: keep order in get_values_from_single (#24907)
* fix: keep order in `get_values_from_single`

* fix: add test for destructuring

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
2024-02-19 05:35:35 +00:00
Akhil Narang
26ae0f3460
fix: ruff fixes
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-02-07 17:04:31 +05:30
Ankush Menat
de9ac89748 style: re-format with ruff 2024-02-05 18:53:33 +05:30
Ankush Menat
a2525e545a
perf: Unbuffered cursors for large result sets (#24365)
If you're reading 1000s of rows from MySQL, the default behaviour is to
read all of them in memory at once.

One of the use case for reading large rows is reporting where a lot of
data is read and then processed in Python. The read row is hoever not
used again but still consumes memory until entire function exits.

SSCursor (Server Side Cursor) allows fetching one row at a time.

Note: This is slower than fetching everything at once AND has risk of
connection loss. So, don't use this as a crutch. If possible rewrite
code so processing is done in SQL.
2024-01-16 11:00:12 +05:30
Ankush Menat
588157df74 feat: frappe.db.sql results as iterator
- Also avoid self.last_result that holds on to large result set reference.
2024-01-15 12:32:02 +05:30
Ankush Menat
e45e313bfb
feat: Skip locked rows while selecting (#24298) 2024-01-13 09:49:27 +05:30