hugapi/hug

Body parameters shadows query parameters

Open

#827 aperta il 2 ott 2019

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)Python (389 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (6758 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor