hugapi/hug

Body parameters shadows query parameters

Open

#827 opened on Oct 2, 2019

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Python (6,758 stars) (389 forks)batch import
enhancementhelp wanted

Description

More an edge case than a real issue: if a body parameters has the exact same name as a query parameter, then the body parameter will override the value.

For example, consider this route definition (with MySchema defined elsewhere)

import falcon
import hug
from marshmallow import fields
@hug.post(["test/{param_1}/route/{param_2}"], status=falcon.HTTP_201)
def my_route(
    request,
    response,
    param_1: fields.Str(description="A param"),
    param_2: fields.Str(description="Another param"),
    body: MySchema(),
):
    print(param_1)
    print(param_2)

If I call it like that

POST /test/first_value/route/second_value
[...]
{
  "body_param": "a body param value",
  "param_2": "overwritten_value"
}

then the output will be

first_value
overwritten_value

Even if MySchema does not define param_2 (stripping param_2 key from the body), the value gets overwritten.

Contributor guide