Skip to content

json_encode_body cannot be overridden if True in API #41

@denravonska

Description

@denravonska

The client allows you to set json_encode_body on both API (global to the API?) and on the resources (local to the resource?). This works fine in a scenario where you have many non-JSON resources and a few JSON resources. In that case you can set json_encode_body=False in the API and True in the resources.

The problem, due to this line is that you can't do the opposite. If the encoding is set to True in the API then all resources use JSON encoding.

An option would be to default the argument to None:

def add_resource(
        self,
        ...
        json_encode_body=None,
    ):
        ...
        resource = resource_class(
            ...
            json_encode_body=json_encode_body if json_encode_body is not None or self.json_encode_body
        )

Slightly less elegant and slightly less consistent with the other calls. A better way, if it works, is to default the argument to whatever the API flag is:

def add_resource(
        self,
        ...
        json_encode_body=self.json_encode_body,
    ):
        ...
        resource = resource_class(
            ...
            json_encode_body=json_encode_body
        )

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions