Skip to content

aiohttp: json payload ignored when data keyword is set to None instead of being absent. #623

Open
@leorochael

Description

@leorochael

In vcr/stubs/aiohttp_stubs.py:vcr_request(), the new_request() coroutine checks for data or jsonwith this:

        data = kwargs.get("data", kwargs.get("json"))

But this line assumes that json can only be sent if data is absent. But data could be present and set to None, along with a json parameter that is not None.

In the case of a None in data and a payload in json, the json payload is ignored, and the cassete is recorded as:

interactions:
- request:
    body: null

The equivalent logic in aiohttp itself is tolerant of a None being present in data (as it must, since None is the default value of both arguments):

        if data is not None and json is not None:
            raise ValueError(
                "data and json parameters can not be used at the same time"
            )
        elif json is not None:
            data = payload.JsonPayload(json, dumps=self._json_serialize)

I recommend the logic in vcr/stubs/aiohttp_stubs.py:vcr_request() be changed to match aiohttp.client:

        data = kwargs.get("data")
        if data is None:
            data = kwargs.get("json")
        elif kwargs.get("json") is not None:
            raise ValueError(
                "data and json parameters can not be used at the same time"
            )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions