Commit graph

40603 commits

Author SHA1 Message Date
Gavin D'souza
d978ed7d06 refactor: Raise FrappeTypeError in case of type mismatches 2022-12-15 13:47:05 +05:30
Gavin D'souza
ec931004ca refactor: transform_parameter_types
Failfast if args and kwargs or annotations don't exist
2022-12-15 13:47:05 +05:30
Gavin D'souza
579aa124e1 fix(type-check): Convert tuple types to Union 2022-12-15 13:47:05 +05:30
Gavin D'souza
299a017081 fix(type-check): Parse and validate arbitrary objects 2022-12-15 13:47:05 +05:30
Gavin D'souza
4fe260e09e refactor: transform_parameter_types
- Switch to Pydantic which is under continuous development and can
  support more types
- Equivalent Pydantic API will try to transform data if possible
- The previous point makes it such that we don't need to explicitly try
  to parse each stringified int in app code since Pydantic can do this
- Drop typeguard since it did not handle 3.10+ native typing definitions
2022-12-15 13:47:05 +05:30
Gavin D'souza
73b0971a26 test: Add tests for typing validations 2022-12-15 13:47:05 +05:30
Gavin D'souza
2327a56abc fix(File): Correct acceptable types in APIs
- Allow str types for start, page_length in page_length API
- Allow str, list[dict] file_list in move_file API
2022-12-15 13:47:05 +05:30
Gavin D'souza
41d6c791f1 fix: Build args dict correctly 2022-12-15 13:47:05 +05:30
Gavin D'souza
8e125f577e fix(type-check): Allow some slack for bool to be int or float 2022-12-15 13:47:05 +05:30
Gavin D'souza
f3250808f0 fix: Use typeguard to handle base hints
Pre process exceptions that Frappe requires and pass the ruleset to
typeguard's check_type API
2022-12-15 13:47:05 +05:30
Gavin D'souza
eb4aa0a1f3 fix(handler): Use signature to fetch doc method structure 2022-12-15 13:47:05 +05:30
Gavin D'souza
cff0567faf fix(print): Check doc permission before checking related info 2022-12-15 13:47:05 +05:30
Gavin D'souza
d78b967f8d test: Run type validation checks in test mode for whitelisted APIs 2022-12-15 13:47:05 +05:30
Gavin D'souza
3aa1d61f0d fix(whitelisted)!: Raise TypeError instead of ValidationError for unaccepted param types 2022-12-15 13:47:05 +05:30
Gavin D'souza
d8cd1be23b fix: Skip type checking if any allowed type is stringified 2022-12-15 13:47:05 +05:30
Gavin D'souza
d3250f6504 refactor(whitelisted): Add typing hints to APIs
* Refactor type checks defined in APIs
* Remove dead/deprecated kwargs usages
* Added appropriate hints to APIs and consecutive utils defined in the following modules:
 - frappe.realtime
 - frappe.translate
 - frappe.utils.global_search
 - frappe.www.third_party_apps
 - frappe.www.search
 - frappe.www.printview
2022-12-15 13:47:05 +05:30
Gavin D'souza
fa88d5f7d9 refactor(minor): User
- Add typing hints for enabling endpoint runtime checks
- Remove unused parameters from function def and usage
- Update docstring in APIs
- Remove (now) redundant isinstance checks
- Use cached get_system_settings instead of DB call (perf)
2022-12-15 13:47:05 +05:30
Gavin D'souza
6678007a8d fix: Support missing Optional or mismatching annotation types
Allow default types as acceptable values if not included in typing
hints. A common example of this is:

def test_password_strength(new_password: str, user_data: Sequence = None):

where Optional[Sequence] is implicit since default value is None.
2022-12-15 13:47:05 +05:30
Gavin D'souza
3fd74afa47 feat(whitelisted): Runtime typing hints validation
- Run type validations if annotations exist for whitelisted functions
- Run validations only on function calls in presense of frappe.local.request

In action:

```bash
> curl -H 'Content-Type: application/json' 'http://photos:8000/api/method/frappe.handler.download_file' -d '{"file_url": ["!=", "gavin.jpg"]}'
```

Note: This ignores stringified or ForwardRef types. If you want types to
be validated make sure they are not imported under `if TYPE_CHECKING`
blocks
2022-12-15 13:47:05 +05:30
Gavin D'souza
ccbc833c6c feat: runtime check via pydantic
handle localns stringified types
2022-12-15 13:47:05 +05:30
Ankush Menat
06becac459
fix(trim-database): Dont act on non-frappe tables (#19292) 2022-12-15 13:43:28 +05:30
Ankush Menat
e437d0aca2 test: test index after col change too 2022-12-15 13:39:25 +05:30
Ankush Menat
56e1bf31d7 fix: patch to delete duplicate uniq indexes 2022-12-15 13:36:28 +05:30
Ankush Menat
8df845ca35 fix: duplicate unique index when column is altered 2022-12-15 13:36:28 +05:30
Ankush Menat
d27ea5e6da test: unique index on install and alter
There should always be 1 unique index.
2022-12-15 13:36:28 +05:30
Shariq Ansari
d64836c1c4
Merge pull request #19285 from barredterra/remove-unused-html-param 2022-12-15 13:19:01 +05:30
Shariq Ansari
445da1fa99
Merge pull request #19284 from barredterra/download-pdf-with-lang-and-letterhead 2022-12-15 13:12:59 +05:30
Shariq Ansari
7129418fda
Merge pull request #19286 from frappe/fix-has-content 2022-12-15 12:31:26 +05:30
Shariq Ansari
cbb620eb61
Merge branch 'develop' into download-pdf-with-lang-and-letterhead 2022-12-15 12:21:19 +05:30
mergify[bot]
8d9673d296
Merge pull request #19289 from pps190/fix-grammer
fix: grammar mistake in label
2022-12-14 15:03:53 +00:00
Devin Slauenwhite
b522da495e
fix: grammar mistake in label 2022-12-14 09:47:28 -05:00
Hussain Nagaria
da7fd35e49 fix: handle HTML code field's has_content 2022-12-14 19:36:07 +05:30
barredterra
22ea39a442 fix: remove unused html parameter
from `attach_print`and `get_print`
2022-12-14 14:37:56 +01:00
Shariq Ansari
378af5a883
Merge pull request #19283 from shariquerik/bump-editorjs 2022-12-14 18:35:19 +05:30
barredterra
67ede5d533 feat: add parameters language and letter_head to download_pdf 2022-12-14 13:59:46 +01:00
Shariq Ansari
5363e6db15 build(deps): Bump editorjs to 2.26.3 2022-12-14 18:12:26 +05:30
Shariq Ansari
a6cecf10b2
Merge branch 'develop' into bump-editorjs 2022-12-14 18:05:26 +05:30
Shariq Ansari
b10056f9cd build(deps): Bump editorjs to 2.26.2 2022-12-14 18:03:27 +05:30
Shariq Ansari
090f55957e
Merge pull request #19280 from shariquerik/grid-custom-button-space 2022-12-14 17:48:38 +05:30
Shariq Ansari
4b1f65206f fix: if grid custom button is not set grid has some extra space on top 2022-12-14 17:29:58 +05:30
Ankush Menat
d13ab320b7 refactor: Duplicate enqueue checks
scheduled_job_type.enqueue already does check for duplicate job and is
more "recent"
2022-12-14 15:46:46 +05:30
Ankush Menat
2b050f9fc3 test: test without adding hacky flags 2022-12-14 15:46:46 +05:30
Ankush Menat
82d699a801 refactor: misleading "log and raise" and types 2022-12-14 15:46:46 +05:30
Devin Slauenwhite
1fc2639123
fix: hide toolbar label (#19272) 2022-12-14 11:03:51 +05:30
Shariq Ansari
6dab439f42
Merge pull request #19269 from shariquerik/web-form-print-format-fix 2022-12-13 18:57:44 +05:30
Shariq Ansari
55d3bea05b
Merge branch 'develop' into web-form-print-format-fix 2022-12-13 18:06:03 +05:30
Shariq Ansari
2767580732 fix: in web form if print format is empty getting error 2022-12-13 17:41:10 +05:30
Ankush Menat
b91354e28f
Merge pull request #19265 from ankush/prepared_report_sort
fix: sort keys in prepared report filters
2022-12-13 16:50:01 +05:30
Ankush Menat
004c716a67 fix: sort keys in prepared report filters 2022-12-13 16:24:11 +05:30
Ankush Menat
170b7c9b0f chore: correct devel version 2022-12-13 14:20:55 +05:30