* fix(apps): add type hints to whitelisted methods
* fix(recorder): add type hints to whitelisted methods
* fix(comments): add type hints to whitelisted methods
* fix(oauth2): add type hints to whitelisted methods
* fix(google_calendar): add type hints to whitelisted methods
* fix(print): add type hints to whitelisted methods
* fix(print_format_builder): add type hints to whitelisted methods
* refactor(network_printer_settings): remove unused args
* fix(document): add type hints to whitelisted methods
* fix(user_settings): add type hints to whitelisted methods
* fix(mapper): add type hints to whitelisted methods
* fix(connected_app): add type hints to whitelisted methods
* fix(google_contacts): add type hints to whitelisted methods
* fix(frappecloud_billing): add type hints to whitelisted methods
* test: rewrite test to fit the strict type check
* fix(social_login_key): add type hints to whitelisted methods
* fix(share): add type hints to whitelisted methods
* fix(webhook): add type hints to whitelisted methods
* fix(workflow): add type hints to whitelisted methods
* fix(workflow main): add type hints to whitelisted methods
* fix(workflow_action): add type hints to whitelisted methods
* fix: flexible type hint
* fix(client): add type hints to whitelisted methods
* fix: fix some of the tighter types
* fix(frappecloud_billing): add str typehint to whitelisted endpoint
* fix: target_doc can be dict/json string
---------
Co-authored-by: Ankush Menat <ankush@frappe.io>
* feat: global `frappe.in_test` flag
* feat: helper utility to toggle `frappe.in_test`
* fix: use `toggle_test_mode` util
* fix: use `frappe.in_test`
* chore: add comment explaining global `in_test`
* chore: ignore commit replacing flag usage
* test: temporarily disable `frappe.in_test`
this worked earlier because flag was set in werkzeug.local which was separate for API test client
* test: add comment explaining change
This get+conditional set is also slightly prone to data races, but
doesn't seem to be harmful as of now.
Rationale:
- To enable recorder one must first send a request, so this should be
set long before.
- While enabling we can accidentally clear cache for another worker by
invalidating it, but that is kind of acceptable behaviour. We ONLY set
it to False when `None` is received from Redis. Local invalidations
remove it completely.
WIP:
- [x] Basic working feature
- [ ] Make this optional, this has insanely high overhead.
- [ ] Specify requests/function filter to profile/record. This will
allow better recording in production sites.
- [ ] Make SQL profiling optional too
* Revert "fix(test_recorder): get the correct request (#24143)"
This reverts commit 745080c56e.
* test: disable recording before running assertions
* test: Dont set emails in test for broken email setup
* fix: Show server script name in traceback
* chore: typo
Co-authored-by: Sagar Vora <sagar@resilient.tech>
---------
Co-authored-by: Sagar Vora <sagar@resilient.tech>
Attempt to normalize query by removing "variables"
This gives a different view of similar duplicate queries.
These two are distinct queries:
```sql
select * from user where name = 'x'
select * from user where name = 'z'
```
But their "normalized" form would be same:
```sql
select * from user where name = ?
```
This helps highlight queries ran in loop which might not register as
duplicate but are possibly "duplicate".
By processing `EXPLAIN` of queries in background after recording is
completed, the overhead reduces significantly and hence can be used
"more" in production environment too.
Currently frappe recorder can be enabled globally and profiles every
request. This is often way too much info. If you already know where
problem lies you use this decorator sparingly to only profile relevant
functions.
Usage:
```py
from frappe.recorder import record_queries
@record_queries
def sus_slow_function():
frappe.db.sql("select everything from everywhere")
```
* fix: use monotonic time for timing code
`time.time()` depends on system clock which can drift away and get corrected
over time. If you're unlucky it will get corrected in your timing code
and give absurd results.
* test: dont check for status
can refresh and give wrong output
[skip ci]
refactor: clean up code to py39+ supported syntax
- f-strings instead of format
- latest typing support instead of pre 3.9 TitleCase
- remove UTF-8 declarations.
- many more changes
Powered by https://github.com/asottile/pyupgrade/ + manual cleanups
Converted all possible usages of re.* that weren't compiling the regex
separately and re-using it. Separated out the compiled patterns as
global variables. Repetitive patterns could be made DRY-er.
Would be nicer to have all regexes in a single module so that we could
re-use better, keep track of outdated, and keep checks for possible
reDos' etc
The license.txt file has been replaced with LICENSE for quite a while
now. INAL but it didn't seem accurate to say "hey, checkout license.txt
although there's no such file". Apart from this, there were
inconsistencies in the headers altogether...this change brings
consistency.
* Remove six for PY2 compatability since our dependencies are not, PY2
is legacy.
* Removed usages of utils from future/past libraries since they are
deprecated. This includes 'from __future__ ...' and 'from past...'
statements.
* Removed compatibility imports for PY2, switched from six imports to
standard library imports.
* Removed utils code blocks that handle operations depending on PY2/3
versions.
* Removed 'from __future__ ...' lines from templates/code generators
* Used PY3 syntaxes in place of PY2 compatible blocks. eg: metaclass