Commit graph

82 commits

Author SHA1 Message Date
Ankush Menat
81b37cb7d2
refactor: clean up code to py310 supported features (#17367)
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
2022-07-01 11:51:05 +05:30
Ankush Menat
813dcc1848
Revert "feat: Adding support to Query engine" 2022-06-29 23:30:23 +05:30
gavin
91e76ff874
Merge branch 'develop' into get-all-mod 2022-06-28 19:47:20 +05:30
Aradhya
7732accded feat: Attached Engine object to qb & added dynamic type hints 2022-06-28 19:43:23 +05:30
Aradhya
960952cfc3 feat(qb-engine): Added Aggregation function support
* Added Min, Max
* Added tests
2022-06-28 19:41:39 +05:30
Aradhya
d0680941ad refactor: frappe.qb.engine
* feat: supporting empty iterables for Contains objects
* fix: explicitly setting empty iterables as tuples to support more operators
* feat: Added locate to frappe.qb Functions
* feat: Added support for functions passed as strings in fields
* feat: Included Criterion objects as fields
* fix: picking up only function intended fields to pass to get_function_objects
* feat: Added iterable for available functions, added support for Field objects
* fix: fixed * passed in fields in lists
2022-06-28 19:41:23 +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
Gavin D'souza
64e5273764 perf: Patch qb only once - not on every init 2022-06-13 18:39:56 +05:30
gavin
6db1038501 refactor(qb): Rename term subqry to SubQuery
"SubQuery" conforms with terms naming in PyPika. Kept subqry that points
to same def for maintaining APIs.
2022-05-27 16:55:54 +05:30
saxenabhishek
1df3e8f5e7 test: test agg funtions 2022-05-16 15:20:23 +05:30
saxenabhishek
846b89a703 test: test cast funtion 2022-05-16 15:20:23 +05:30
saxenabhishek
e59c2f7b04 test: match edge case 2022-05-16 15:20:23 +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
Suraj Shetty
c0c5b2ebdd
style: format all python files using black (#16453)
Co-authored-by: Frappe Bot <developers@frappe.io>
2022-04-12 10:59:25 +05:30
Abhishek Saxena
5c8856d66e
refactor: db.sql calls to frappe.qb (#16107)
# Changes

- Introduces `subqry` class to use in where clause when there is a non-column condition. eg.
> .where(subqry(no_of_roles) == 0)
- Convert SQL queries to frappe.qb 

# Testing

Functions with query refactors
- frappe.boot.get_user_pages_or_reports() -> Same output of `get_bootinfo()` as develop
- frappe.boot.get_unseen_notes() -> Forms the same query as develop 
```sql
SELECT `name`,`title`,`content`,`notify_on_every_login`
FROM `tabNote` WHERE `notify_on_every_login`=1
AND `expire_notification_on`>'2022-03-30 01:10:53.393874'
AND (SELECT `nsb`.`user` FROM `tabNote Seen By` `nsb` WHERE `nsb`.`parent`=`tabNote`.`name`) NOT IN ('Administrator')
```
- frappe.installer._delete_doctypes() -> installed and uninsalled a dummy app to drop tables

### Not tested
- frappe.make_property_setter()
- frappe.realtime.get_pending_tasks_for_doc() [whitelist method]
- frappe.sessions.Session.start()
- frappe.twofactor.cache_2fa_data()
2022-04-12 05:07:25 +00:00
Gavin D'souza
2d806b5d6d fix: Ported subqry to branch for compatibility
Via https://github.com/frappe/frappe/pull/16107
2022-03-31 13:41:08 +05:30
Gavin D'souza
71d3f1c0d1 feat(minor): Add DateFormat function util for qb 2022-03-31 13:39:06 +05:30
Ritwik Puri
0d16c20f93
test: tests for Cast_ Function in qb (#16399)
* test: tests for Cast_ Function in qb

* test: remove unneeded sync

Co-authored-by: Mohammad Hasnain <hasnain2808@gmail.com>
2022-03-25 14:46:08 +05:30
Mohammad Hasnain Mohsin Rajan
fda544f424
refactor!: make automatically following documents optional (#16030)
* fix: make automatically following documents optional

* fix: optimize email triggers for document followed

* test: add tests for document follow settings

* test: sync global search before testing

* fix: extend pypika's cast function to mimic varchar cast in MariaDB

Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>
Co-authored-by: phot0n <ritwikpuri5678@gmail.com>
2022-03-25 02:01:15 +05:30
Ankush Menat
b029b255fe refactor: code duplication for sql whitelisting 2022-03-24 17:49:28 +05:30
Gavin D'souza
f92f77dab7 fix(qb): Make Table importable 2022-03-22 20:31:37 +05:30
Ankush Menat
1a0fb21645 feat: MySQL TIMESTAMP functionality for QB 2022-03-16 15:13:04 +05:30
Ankush Menat
496e5b513b fix: executing non-select qb code from whitelisted methods
Co-Authored-By: Gavin D'souza <gavin18d@gmail.com>
2022-02-08 13:06:24 +05:30
saxenabhishek
44d7940746 fix: missing param_wrapper in recursive calls 2022-02-03 12:32:47 +05:30
Gavin D'souza
229e259bd2 fix: Format timedelta object accurately 2022-01-31 11:56:09 +05:30
saxenabhishek
97d6a96419 fix: timedelta parsing in pypika 2022-01-25 13:28:11 +05:30
saxenabhishek
02bdc35490 fix: make parameters for strings only 2022-01-15 14:55:28 +05:30
saxenabhishek
9121014f48 fix: ignore copy of getattr methods 2022-01-11 16:53:42 +05:30
saxenabhishek
ece1564e4d fix: replace the field method with a column 2022-01-11 15:32:07 +05:30
saxenabhishek
471c0bd697 docs: Working of NamedParameters in qb 2022-01-11 01:01:44 +05:30
saxenabhishek
e2d49c17ff refactor: remove reduandant func call 2022-01-11 01:01:44 +05:30
saxenabhishek
0f75394720 refactor: pythonic NamedParameterWrapper 2022-01-11 01:01:44 +05:30
Gavin D'souza
f6fba91fd2 chore(typing): Add type hints in qb builder classes 2022-01-10 13:44:23 +05:30
Gavin D'souza
04e79eb075 fix(qb:ValueWrapper): Use get_value_sql only for str values 2022-01-10 13:25:47 +05:30
Gavin D'souza
6aa9a0bef5 style: Sorted imports & whitespace consistency 2022-01-07 20:44:51 +05:30
Gavin D'souza
34a6f7adb5 fix(qb): Patch ParameterizedValueWrapper as wrapper_cls 2022-01-07 20:43:50 +05:30
Suraj Shetty
e8ced74901
Merge branch 'develop' into aks-feat-sanitise_qb_2 2021-12-12 10:16:26 +05:30
saxenabhishek
a71795afec docs: ConstantColumn 2021-12-08 15:46:30 +05:30
saxenabhishek
9a393e5654 fix: postgres compatibility 2021-12-08 15:43:22 +05:30
Suraj Shetty
5c34405d8a
Merge branch 'develop' into aks-feat-constCol 2021-12-08 09:33:50 +05:30
saxenabhishek
4f7c8d066a feat: build constant value cols 2021-12-07 20:55:38 +05:30
Suraj Shetty
99defea410
fix: Explicitly ignore semgrep warning 2021-12-07 16:40:45 +05:30
saxenabhishek
6120b4b3c1 fix: extend named parameters to frappe.qb.function 2021-12-06 14:32:55 +05:30
saxenabhishek
9fdacedfc8 feat: sanitise frappe.qb 2021-12-06 14:29:57 +05:30
saxenabhishek
a574c1ba88 chore: patching ValueWrapper 2021-12-06 14:27:42 +05:30
Aradhya
3243fb2083 fix: misc fixes 2021-12-06 13:04:27 +05:30
Aradhya
69108c4c86 Merge branch 'develop' of github.com:Aradhya-Tripathi/frappe into at/aggregations 2021-11-27 17:52:30 +05:30
Aradhya
b5c73648dc refactor: made DRY-er functions 2021-11-26 15:44:14 +05:30
Aradhya
e3bdf11006 refactor: moved aggregation functions to Query Builder 2021-11-26 14:19:59 +05:30
Aradhya
22434d065c feat: Added aggregation functions to qb functions
refactor: changed args to aggregation funcs to match db level aggregation funcs
2021-11-26 13:19:26 +05:30