hugapi/hug

Body parameters shadows query parameters

Open

#827 ouverte le 2 oct. 2019

Voir sur GitHub
 (3 commentaires) (0 réactions) (0 assignés)Python (389 forks)batch import
enhancementhelp wanted

Métriques du dépôt

Stars
 (6 758 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

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.

Guide contributeur