Commit graph

217 commits

Author SHA1 Message Date
Ankush Menat
507343f4f6 fix: double response processing 2023-10-16 18:12:53 +05:30
Ankush Menat
e0f87dc4e1 refactor!: move OAuth and token auth code to auth.py
This doesn't belong in api.py
2023-10-16 18:12:53 +05:30
Ankush Menat
5af6624cce refactor: Use werkzeug router for API routing 2023-10-16 18:12:53 +05:30
Ankush Menat
c7338f5a83 chore: deprecate form_dict.cmd, globals() 2023-10-16 18:12:53 +05:30
barredterra
ed2290d1d6 Merge branch 'develop' into feat/improve-openid-connect-devx 2023-10-07 15:22:59 +02:00
Ankush Menat
56371f09e0 Revert "fix!: Bind development server only to localhost (#22397)"
This reverts commit 9244140816.

Breaks docker development installs
2023-09-20 11:43:56 +05:30
David Arnold
64a09be958
Merge branch 'develop' into feat/improve-openid-connect-devx 2023-09-16 09:58:53 +02:00
Ankush Menat
530c47ffe5
feat: after_response callback manager (#22398)
* feat: `after_response` callback manager

* perf: defer closing DB connection

* refactor: simplify after response hooks

* wip

* example usage

---------

Co-authored-by: Sagar Vora <sagar@resilient.tech>

* fix: Log request end if not already

---------

Co-authored-by: Sagar Vora <sagar@resilient.tech>
2023-09-14 10:56:08 +00:00
Ankush Menat
9244140816
fix!: Bind development server only to localhost (#22397) 2023-09-13 17:26:19 +05:30
0xsaif
aa7ee1c6b9
refactor: force ipv4 localhost (#22394)
* reafctor: force ipv4 localhost

Replacing "localhost" with "127.0.0.1" in the codebase; sometimes the name localhost force-resolves to ipv6

* revert: leave localhost usage in oauth tests

Change not required.

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
2023-09-13 16:23:23 +05:30
Ankush Menat
4a5e584ad0
refactor: escape instead of sanitizing HTML (#22339)
Traceback if it contains HTML can be useful, better to escape and show
instead of modifying it.
2023-09-10 09:43:47 +00:00
David Arnold
87684e2647
feat: add werkzeug proxyfix to development server 2023-09-07 01:30:25 +02:00
Ankush Menat
07ff74edc5
feat: send unique request id as response header (#22218) 2023-08-28 13:19:34 +05:30
Ankush Menat
48f72655ad
feat(dx): Run gunicorn in development setup (#22088)
This lets developer run gunicorn in development setup while still being
able to use statics/assets.

While this is not "first class" support, it's usable for me. I don't see
need for more right now. Making this default in developer mode isn't
ideal IMO as it's quite heavy compared to werkzeug (and no debugger or
decent request logging)

To use in development mode swap `bench serve` with gunicorn command,
refer gunicorn config docs for more info.

```diff
- web: bench serve --port 8000
+ unicorn: gunicorn -b 127.0.0.1:8000 -w 1 --chdir /home/user/benches/develop/sites 'frappe.app:application_with_statics()' --preload
```

`no-docs`
2023-08-17 11:34:45 +05:30
gavin
6cb51a536e
fix: re module cache settings - purge & cache size (#21808)
* fix: Remove re cache internals manipulation

* fix: Purge re cache after module loads

Empty cache would work better as we already got our pre-compiled
patterns at the top level of every module. This leaves the cache open
for dynamically generated patterns which are in better need of it. Over
time, workers would converge to this anyway. This change only reduces
the cache hit and eviction effort.

I'd improve this by executing `re.purge` on every module import but
complexity tradeoff lol. I'd prefer if re didn't cache patterns
generated by `re.compile` but I dont see this behaviour or any escape
hatches so this will have to do for now.
2023-07-27 10:40:50 +05:30
Ankush Menat
3f142c1dce fix: respect system setting for tracebacks
closes https://github.com/frappe/frappe/issues/19826
2023-07-16 19:18:16 +05:30
Ankush Menat
d7990368a8
perf: preload more modules (#21557)
* perf: preload more modules

- bleach is used frequently for sanitization
- File gets imported anytime a private file is viewed. Indirect import
  of PIL is costly in each worker.

* test: warm up perf test
2023-07-02 21:47:21 +05:30
Ankush Menat
265a28e151 perf: preload pydantic 2023-07-02 16:32:40 +05:30
Ankush Menat
b9f000e1f9 refactor!: Log 5xx error to error log instead of error snapshot
Also move log_error function to right location
2023-06-28 10:59:19 +05:30
Ankush Menat
af03b76c88 perf: Preload and share common python modules 2023-06-24 21:24:02 +05:30
Ankush Menat
150c36c74d fix: collect before freezing 2023-06-24 17:36:10 +05:30
Ankush Menat
fbe3174914 perf: Bump alloc count to 7,000 for generation 0
This has overall 1-2% CPU usage reduction for little to no costs.
Benefits increase when doing bulk processing with lots of objects.
2023-06-24 17:02:45 +05:30
Ankush Menat
4f0a2e6e9c fix: move gc.freeze behind environ variable 2023-06-24 16:35:34 +05:30
Ankush Menat
423e781326 perf: Freeze GC before forking Gunicorn workers 2023-06-24 15:23:52 +05:30
Sagar Vora
e1764d5a4b
feat: log pid and user in request logs (#21267) 2023-06-08 19:43:29 +05:30
Ankush Menat
5185374f72
refactor!: Remove dynamic addition of _comments (#21217)
This isn't required anymore, was added to handle old sites.
2023-06-02 21:57:58 +05:30
Ankush Menat
1e9ede40fa
fix: stale frappe.local (#20695)
* fix: stale `frappe.local`

Co-Authored-By: Aditya Hase <aditya@adityahase.com>

* fix: force re-init in request

To ensure that any one bad request can not completely cause recurring
loop of broken requests due to bad locals, we just force-init locals on
every request.

---------

Co-authored-by: Aditya Hase <aditya@adityahase.com>
2023-04-14 14:19:01 +05:30
Gavin D'souza
9e87596cf1 fix: Run after_hooks only if site is initialized 2023-03-01 16:52:58 +05:30
Gavin D'souza
5d0bd512e1 fix(after_hook): Don't pass exception object to hook
* it can fetch most relevant details via response object
* Exceptions not supported by Frappe's WSGI (unsupported HTTP methods) may not be accessible to the after_request hooks - but the lack of active response may be an indicator / and peeking in the request
2023-02-17 11:24:01 +05:30
Gavin D'souza
fe26c542b7 refactor: Move before/after tasks as hooks
Moved before/after tasks in Requests as hooks for:
- monitor
- rate_limiter
- recorder

Moved before/after tasks in Jobs as hooks for:
- monitor
- releasing document locks
2023-02-15 15:30:02 +05:30
Gavin D'souza
6d70b5e934 fix(app): Move after_request hook inside finally block
Also, rename after_request fn to sync_database to better match functionality
2023-02-15 14:52:08 +05:30
Gavin D'souza
825f1d32f1 Merge branch 'develop' into request-job-hooks 2023-02-15 12:57:14 +05:30
Gavin D'souza
18eabf5153 fix(dx): Don't reload web workers if tests are changed in dev server 2023-02-10 14:39:39 +05:30
Gavin D'souza
d6a41cd272 feat: Before/After Request Hooks 2023-02-09 15:49:47 +05:30
Ankush Menat
4f162da728 fix: rollback if not commiting 2022-11-28 11:43:41 +05:30
Ankush Menat
4cc367f6c1 fix: apply rollback to all HTTP methods that can write 2022-11-28 11:34:46 +05:30
Ankush Menat
7504c1bc73 refactor: simpler commit after_request 2022-11-28 11:31:24 +05:30
Ankush Menat
1f6f31fc97 refactor: int > cint 2022-11-17 11:35:24 +05:30
Athul Cyriac Ajay
190e01a5f3 fix: Force integer type in request.max_content_length 2022-11-17 11:35:24 +05:30
Ankush Menat
9fc330ea6c
Revert "fix: remove middleware to clear frappe.local (#18874)" (#18886)
This reverts commit 2971abe517.
2022-11-15 18:45:51 +05:30
Sagar Vora
2971abe517
fix: remove middleware to clear frappe.local (#18874) 2022-11-15 11:07:18 +05:30
Ankush Menat
db1ed206f3 fix: only release db if it exists
ref https://github.com/frappe/frappe/pull/18772

[skip ci]
2022-11-06 18:54:18 +05:30
Sagar Vora
cd1bbccdc3
fix: dont release frappe.local twice (#18772) 2022-11-05 21:35:37 +05:30
Sagar Vora
f20fa69282
fix!: remove relaxations for Cordova (#18728) 2022-11-04 17:24:26 +05:30
Sagar Vora
709c9305ae
chore: remove unused RequestContext class (#18152) 2022-09-15 23:22:14 +05:30
Ankush Menat
d19790e03d fix: error handling without user set 2022-09-10 12:45:25 +05:30
Ankush Menat
98b57f6a1a fix: ensure deferred insert are flushed during update 2022-09-09 17:34:46 +05:30
Ankush Menat
5beccd8802 feat: allow reads during maintenance_mode
To reduce downtime reading from main db server during maintenance_mode
can be allowed. This lets users browse desk, static sites or any other
pages while ensuring that no writes happen to DB.

refactor: use read replica if available
2022-09-08 18:22:03 +05:30
Ankush Menat
022df94711
fix: respect Accept headers during maintenance mode #18057 2022-09-08 14:35:55 +05:30
Sagar Vora
48196915f6 fix: set Vary header to tell browser that response differs based on origin 2022-09-05 15:42:08 +05:30