Commit graph

1521 commits

Author SHA1 Message Date
gavin
574f160d3c
Merge branch 'develop' into mariadb-client-refactor 2022-06-23 16:13:03 +05:30
Deepesh Garg
26d0e7a0f9
fix: App logo not set in website settings (#17261)
* fix: App logo not set in website settings

* chore: potential error in system settings
2022-06-21 20:07:59 +05:30
gavin
73f6141e0d
Merge branch 'develop' into mariadb-client-refactor 2022-06-20 15:31:53 +05:30
Gavin D'souza
14003e5ac9 refactor: DISABLE_DATABASE_CONNECTION_POOLING conf + var name 2022-06-20 15:31:15 +05:30
Raffael Meyer
7b67e1f847
fix: translate doctype in error messages (#17239) 2022-06-20 10:35:57 +05:30
Gavin D'souza
b4578dc632 Merge branch 'develop' of github.com:frappe/frappe into mariadb-client-refactor 2022-06-15 16:40:29 +05:30
Gavin D'souza
36fa2122a3 fix: Patch qb for different schemas in same process
You would want to switch schemas in the same process. Eversince the
change
64e5273764
we stopped patching on every frappe.init call which meant, if a MariaDB
site was initialized first, frappe._qb_patched would be set to True and
if a Postgres site was initialized after, _qb_patched would be lying as
the PG engine isn't patched yet. Sooooo we need a Dict instead to
maintain this record of patching. This issue caused weird errors lol -

Traceback:

  File "/home/frappe/Desktop/frappe-bench-dev/env/lib/python3.10/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/commands/__init__.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/commands/site.py", line 524, in migrate
    SiteMigration(
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/migrate.py", line 169, in run
    self.setUp()
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/migrate.py", line 73, in setUp
    clear_global_cache()
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/cache_manager.py", line 102, in clear_global_cache
    clear_website_cache()
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/website/utils.py", line 374, in clear_website_cache
    clear_cache(path)
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/website/utils.py", line 369, in clear_cache
    for method in frappe.get_hooks("website_clear_cache"):
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/__init__.py", line 1440, in get_hooks
    hooks = _dict(_load_app_hooks())
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/utils/caching.py", line 57, in wrapper
    return_val = func(*args, **kwargs)
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/__init__.py", line 1407, in _load_app_hooks
    apps = [app_name] if app_name else get_installed_apps(sort=True)
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/utils/caching.py", line 57, in wrapper
    return_val = func(*args, **kwargs)
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/__init__.py", line 1374, in get_installed_apps
    installed = json.loads(db.get_global("installed_apps") or "[]")
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/database/database.py", line 917, in get_global
    return self.get_default(key, user)
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/database/database.py", line 921, in get_default
    d = self.get_defaults(key, parent)
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/database/database.py", line 938, in get_defaults
    defaults = frappe.defaults.get_defaults(parent)
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/defaults.py", line 88, in get_defaults
    globald = get_defaults_for()
  File "/home/frappe/Desktop/frappe-bench-dev/apps/frappe/frappe/defaults.py", line 218, in get_defaults_for
    frappe.qb.from_(table)
TypeError: 'Field' object is not callable
2022-06-15 15:55:43 +05:30
Ankush Menat
ea416f9d6b feat: log settings with "interface"
We have hardcoded "Log settings" to only apply on 3 doctypes, there are
few more logging doctypes in core which are not cleared right now, on
top of that it's not easy for user to configure all logging behaviour
from one place.

This change adds a table on log settings where logging doctypes that
support the interface required by log settings can auto-register and
show up in settings.

Currently only supported configuration is "number of days" to keep.
2022-06-15 12:30:38 +05:30
Gavin D'souza
80b19a6031 fix: Cast singles_dict' values
This is to adapt with the changes made in frappe.db.get_singles_dict in
the previous commit
2022-06-15 10:40:26 +05:30
Gavin D'souza
678eebe4fb perf: Limit re internal cache to avoid caching patterns twice 2022-06-14 17:16:34 +05:30
Gavin D'souza
e681233e98 perf: Fetch and cache entire settings' dicts 2022-06-13 18:39:56 +05:30
Gavin D'souza
64e5273764 perf: Patch qb only once - not on every init 2022-06-13 18:39:56 +05:30
Gavin D'souza
54dd72b8da chore: Import sys in msgprint's namespace 2022-06-09 12:43:56 +05:30
gavin
9ce74fb6c4
Merge branch 'develop' into request-cache 2022-06-09 12:32:03 +05:30
Sagar Vora
df28f32b8b
perf: ~90% faster frappe.get_cached_doc (#17107) 2022-06-08 15:49:11 +05:30
gavin
44dba28159
Merge branch 'develop' into refactor-file 2022-06-08 12:43:35 +05:30
Gavin D'souza
9f2d3bf33e fix: Clear site_cache, request_cache on clear_cache 2022-06-07 18:17:44 +05:30
Gavin D'souza
39fe348ee9 perf: frappe.get_hooks
From 115 µs ± 2.31 µs to 2.69 µs ± 27 ns per call

Changes:
* Use request_cache over get_installed_apps, _load_app_hooks
* Refactor logic for default - so that None is an acceptable value
* Remove handling of webnotes app in get_hooks - 8yo code ^_^
2022-06-07 18:09:57 +05:30
Ankush Menat
111df3a8d7 perf: improve document caching
As per current implementation whenever `get_doc` is called, document is
cached. However, this cache is only ever used by `get_cached_doc`. Going
through the codebase of both FF/ERPNext you'll find that `get_doc` is
used a lot more than `get_cached_doc`. So in many places, all this
caching overhead is unnecessary.

This change removes implicit caching from get_doc and replaces it with
cache-replacement instead. i.e. cache is only updated if it exists but
not created from get_doc.

Pros:
- faster `get_doc`
- lower memory usage on Redis
- Reduces chances of OOM by blowing up worker's memory as old docs can't
  be GCed until
- Correctness i.e. caching only what gets used from cache.

Con:
- After this change. First call to `get_cached_doc` will always be a cache miss. DUH.
2022-06-06 16:18:23 +05:30
Gavin D'souza
5ec2690160 Merge branch 'develop' into refactor-file 2022-06-01 15:47:55 +05:30
Ankush Menat
f8f29e284f
perf: store compact JSON in version diffs (#17042) 2022-05-31 22:40:07 +05:30
Ankush Menat
75b7a823a9
Merge pull request #17009 from ankush/delete_doctype_changes
fix!: dont delete customizations when doctypes are deleted
2022-05-30 21:00:50 +05:30
Ankush Menat
4085646495 fix: identify varkw in get_newargs 2022-05-29 17:11:58 +05:30
Ankush Menat
1e64abe9a5 fix!: meaningful error messages over KeyError 2022-05-29 13:46:48 +05:30
gavin
639fa62138 fix: frappe.DISABLE_DATABASE_POOLING to override frappe.conf.disable_database_connection_pooling
Also, don't pool root connections
2022-05-24 19:19:53 +05:30
gavin
cac25f1229 feat(minor): Add support for for_update in get_last_doc 2022-05-24 19:19:53 +05:30
Abhishek M
378149375d
fix: Passing dev server variable to jenv globals correctly (#16843)
Encountered the same issue during a fresh setup: https://discuss.erpnext.com/t/v13-fresh-install-develop-socket-io-using-wrong-port/74562

The problem originates from the `socketio_client.js` file.  During development, the `socket.io` client by default sends request to port 8000 but ideally it should've been 9000 (that's where it's actually running) since the latter is defined in `frappe.boot.socketio_port`. This is happening because the `jenv` variable `dev_server` is always being returned as 0.

In [this](0f7d8e7903/frappe/__init__.py (L237)) line, we are seting `frappe.local.dev_server` but in safe exec we are using `frappe._dev_server` as the source to populate the variable `dev_server` which eventually gets pushed to the `app.html` via `jinja`. (`frappe._dev_server` evaluates to `None`)

In `socketio_client`, we are using [this](0f7d8e7903/frappe/public/js/frappe/socketio_client.js (L112)) variable as a flag to decide whether or not `frappe.boot.socketio_port` should be the port that the `socket.io` client connects to.
2022-05-18 09:19:24 +00:00
Ankush Menat
c55c8e4f97
refactor(DX): add type hints for some utilities (#16871)
- Added type hints to majority of most used functions in `utils/data.py`
- added overloads for functions whose output depends on input type. This helps A LOT if your LSP supports type narrowing (like pyright)


Example:
Same function with 3 diff singatures narrowed by input value. 
<img width="1270" alt="Screenshot 2022-05-10 at 8 02 02 PM" src="https://user-images.githubusercontent.com/9079960/167653595-2ab9441f-da40-4645-aa87-9ec0d96cbec9.png">
2022-05-11 06:14:31 +00:00
Saqib Ansari
61223092e0
fix: frappe.throw in case of list of errors (#16855) 2022-05-09 18:42:54 +05:30
Ritwik Puri
b41379c78b
fix: misc fixes (integer primary keys) (#16307)
* fix: misc fixes

local.x gets resetted on every request so switched to a simple dict

simplified is_val_used in set_next_val function for sequences

* chore: use multisql for sequence methods

* fix: fields not updating on form

* minor(base_input): removed unnecessary branching in update_input

* chore: remove prints and rename autoincremented_status_map

* chore: added proper type hint + comment + formatting

* fix: added searching in cast_name rather than handling it manually

* fix: share condition query + test_build_match_conditions

* fix: add cast_name to more places

* test: test for sequence

* fix: sequence functions

* fix: inherit frappetestcase

* minor: attach sequence methods to db context local

* chore: update sequence function names in Database

use frappe.db for sequences in naming.py

* fix: convert filename to str (for autoincremented doctypes)

* chore: better regex for modifying values for postgres

* minor: allow changing name column type (if no data is present in the doctype)

* refactor: validate_autoname

converted it to a simple function
enabled changing autoincrement autoname from customize form

* fix: use sql_ddl for change_column_type in postgres

* fix: use not null constraint in postgres when changing name type

* fix(test): updated test_autoincremented_doctype_transition with transitioning when no data is present

* fix(test): updated test_cast_name

probably messed up during rebase

* fix(test): used rollback upon error in transaction for postgres

* chore: use frappe.db.x methods for sequences

* minor: use temporary sequences in test

* minor: use generate_hash for sequence naming in sequence tests

* chore: replace sequence imports with frappe.db.x

* chore: move out casting name fields to a separate method

* refactor: cast_name

more explicit cases for casts and added docstring

* fix: added space in test_cast_name

* chore: fix linter

* chore: better naming for can_change_name_column_type

* chore: add comment for autoincremented_site_status_map

* chore: update/add docstrings
2022-04-29 15:06:03 +05:30
gavin
f4394f124a
Merge pull request #16715 from ChillarAnand/v3.11
refactor!: Remove wrapt package
2022-04-27 12:28:13 +05:30
chillaranand
a9492ba5fa refactor: Remove wrapt package
Also replaced inspect.getfullargspec with inspect.signature to
preserve signature of a decorated functions.
2022-04-27 11:36:07 +05:30
gavin
5f2f387a9c
Merge pull request #16130 from gavindsouza/bg-rename_doc
feat: Async Document Renaming
2022-04-26 12:57:31 +05:30
gavin
2da85fa8da
Merge pull request #16698 from gavindsouza/traceback-with-context
feat: Traceback with context
2022-04-22 13:04:07 +05:30
Gavin D'souza
ffc2b9427f Merge branch 'develop' of github.com:frappe/frappe into bg-rename_doc 2022-04-22 12:14:21 +05:30
Gavin D'souza
b6683db57e refactor: frappe.rename_doc definition
Use explicit naming of args, kwargs and don't accept cmd and
ignore_permissions explicitly
2022-04-21 16:09:08 +05:30
Gavin D'souza
5ecc9fe4ff refactor(log_error): de-clutter & log context with traceback 2022-04-21 13:27:01 +05:30
Gavin D'souza
4e533682ba feat: get_traceback with context 2022-04-21 13:26:12 +05:30
Gavin D'souza
1d84483289 Merge branch 'develop' of github.com:frappe/frappe into refactor-file 2022-04-21 11:45:50 +05:30
Gavin D'souza
892e05fdc1 Merge branch 'develop' of github.com:frappe/frappe into bg-rename_doc 2022-04-20 16:04:27 +05:30
Rushabh Mehta
78bddb4127
Merge pull request #16653 from rmehta/error-log-ref
feat(minor): Add document reference to Error Log and doc.log_error
2022-04-20 15:54:59 +05:30
Ankush Menat
dcee40046a
perf!: simpler frappe.get_system_setting (#16685)
Not sure why this needs to be "cached" in locals again when db object
already caches it in value_cache.
2022-04-20 15:16:04 +05:30
Rushabh Mehta
d9fbee3b9c fix(minor): frappe.log_error 2022-04-18 17:29:03 +05:30
Rushabh Mehta
6e6fe9521e fix(linting): no single quotes :'| 2022-04-18 17:29:03 +05:30
Rushabh Mehta
57a55e4225 feat(minor): Add document reference to Error Log and doc.log_error 2022-04-18 17:29:03 +05:30
Gavin D'souza
4b51b72119 Merge branch 'develop' of github.com:frappe/frappe into refactor-file 2022-04-18 17:28:56 +05:30
Gavin D'souza
801874154d fix: Add return value for doc.delete 2022-04-18 12:02:19 +05:30
Gavin D'souza
66655eb8ed Merge branch 'develop' of github.com:frappe/frappe into bg-rename_doc 2022-04-14 13:41:56 +05:30
Gavin D'souza
bfc1b36f18 Merge branch 'reload-doc_force' into modules-refactor 2022-04-14 13:32:20 +05:30
Gavin D'souza
0a854ddd2a chore(frappe): Add typing hints for init methods 2022-04-14 09:57:03 +05:30