feat: runtime check via pydantic
handle localns stringified types
This commit is contained in:
parent
06becac459
commit
ccbc833c6c
2 changed files with 23 additions and 1 deletions
|
|
@ -716,6 +716,27 @@ xss_safe_methods = []
|
|||
allowed_http_methods_for_whitelisted_func = {}
|
||||
|
||||
|
||||
def validate_argument_types(func):
|
||||
return func
|
||||
from pydantic import validate_arguments as pyd_validator
|
||||
|
||||
def validator(*args, **kwargs):
|
||||
return pyd_validator(func)(*args, **kwargs)
|
||||
|
||||
import sys
|
||||
|
||||
# from frappe.model.document import Document
|
||||
# localns = {
|
||||
# "Document": Document,
|
||||
# }
|
||||
|
||||
try:
|
||||
return validator(func)
|
||||
except NameError:
|
||||
sys.stderr.write(f"{func} has unsupported type annotations")
|
||||
return func
|
||||
|
||||
|
||||
def whitelist(allow_guest=False, xss_safe=False, methods=None):
|
||||
"""
|
||||
Decorator for whitelisting a function and making it accessible via HTTP.
|
||||
|
|
@ -753,7 +774,7 @@ def whitelist(allow_guest=False, xss_safe=False, methods=None):
|
|||
if xss_safe:
|
||||
xss_safe_methods.append(fn)
|
||||
|
||||
return method or fn
|
||||
return validate_argument_types(method or fn)
|
||||
|
||||
return innerfn
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ dependencies = [
|
|||
"pyOpenSSL~=22.1.0",
|
||||
"pycryptodome~=3.10.1",
|
||||
"pyotp~=2.6.0",
|
||||
"pydantic~=1.10.2",
|
||||
"python-dateutil~=2.8.1",
|
||||
"pytz==2022.1",
|
||||
"rauth~=0.7.3",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue