8000 feat: support array request type (backport #25109) by mergify[bot] · Pull Request #25112 · frappe/frappe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: support array request type (backport #25109) #25112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions frappe/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,15 @@ def make_form_dict(request: Request):
args.update(request.args or {})
args.update(request.form or {})

if not isinstance(args, dict):
if isinstance(args, dict):
frappe.local.form_dict = frappe._dict(args)
# _ is passed by $.ajax so that the request is not cached by the browser. So, remove _ from form_dict
frappe.local.form_dict.pop("_", None)
elif isinstance(args, list):
frappe.local.form_dict["data"] = args
else:
frappe.throw(_("Invalid request arguments"))

frappe.local.form_dict = frappe._dict(args)

# _ is passed by $.ajax so that the request is not cached by the browser. So, remove _ from form_dict
frappe.local.form_dict.pop("_", None)


def handle_exception(e):
response = None
Expand Down
13 changes: 13 additions & 0 deletions frappe/tests/test_api.py
< 8000 div class="d-flex flex-justify-end">
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ def get_message(resp, msg_type):
self.assertIn("ZeroDivisionError", response.json["exception"]) # WHY?
self.assertIn("Traceback", response.json["exc"])

def test_array_response(self):
method = "frappe.tests.test_api.test_array"

test_data = list(range(5))
response = self.post(self.method_path(method), test_data)

self.assertEqual(response.json["message"], test_data)


class TestReadOnlyMode(FrappeAPITestCase):
"""During migration if read only mode can be enabled.
Expand Down Expand Up @@ -463,3 +471,8 @@ def test(*, fail=False, handled=True, message="Failed"):
1 / 0
else:
frappe.msgprint(message)


@frappe.whitelist(allow_guest=True)
def test_array(data):
return data
0