Skip to content

Commit 98dcdd5

Browse files
committed
Added allow_empty option in verify params decorator
1 parent 5052fcd commit 98dcdd5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

backend/PyMatcha/utils/decorators.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from werkzeug.exceptions import BadRequest
99

1010

11-
def validate_params(required: dict, optional: Optional[dict] = None):
11+
def validate_params(required: dict, optional: Optional[dict] = None, allow_empty=False):
1212
if optional is None:
1313
optional = {}
1414

@@ -43,12 +43,13 @@ def wrapper(*args, **kwargs):
4343
"You are only allowed to specify the fields {}" ".".format(required.keys()),
4444
)
4545

46-
for key, value in data.items():
47-
if not value:
48-
if required[key] == int or required[key] == bool:
49-
pass
50-
else:
51-
raise BadRequestError(f"The item {key} cannot be None or empty.")
46+
if not allow_empty:
47+
for key, value in data.items():
48+
if not value:
49+
if required[key] == int or required[key] == bool:
50+
pass
51+
else:
52+
raise BadRequestError(f"The item {key} cannot be None or empty.")
5253

5354
wrong_types = [r for r in required.keys() if not isinstance(data[r], required[r])]
5455
wrong_types += [r for r in optional.keys() if r in data and not isinstance(data[r], optional[r])]

0 commit comments

Comments
 (0)