Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider accepting params=None for JSON-RPC 1.0 #63

Open
MattFisher opened this issue Jun 13, 2017 · 1 comment
Open

Consider accepting params=None for JSON-RPC 1.0 #63

MattFisher opened this issue Jun 13, 2017 · 1 comment
Assignees

Comments

@MattFisher
Copy link
Contributor

We are dealing with a client library that sends "params": null in a JSON-RPC 1.0 "hello" request, which is rejected by JSONRPC10Request.from_json() (as specifically tested by TestJSONRPC10Request.test_params_validation_none()) because it's not a list.

The JSON-RPC 2.0 Specification states the following:

If present, parameters for the rpc call MUST be provided as a Structured value. Either by-position through an Array or by-name through an Object.

but the JSON-RPC 1.0 Specification just says

params - An Array of objects to pass as arguments to the method

which makes it pretty clear that an empty array is what's expected if you want to pass zero params, but isn't totally definitive on whether null/None is a valid value.

Would it cause any problems to treat null as if it's an empty list for JSON-RPC 1.0?

The implementation might look like:

# JSONRPC10Request
@params.setter
def params(self, value):
    value = value if value is not None else []  # <= New line
    if not isinstance(value, (list, tuple)):
        raise ValueError("Incorrect params {0}".format(value))

    self._data["params"] = list(value)
@pavlov99
Copy link
Owner

Hi, @MattFisher

Sorry for such a late reply. I was out of python development for a while.

As you have mentioned, there is a liss.hello() call without parameters. I would argue that it is better to change the client to use an empty list in parameters. According to the specification json-rpc 1.0 does not expect to receive null. If we make a patch for that case it might affect other users.

The other method is to explicitly set params to an empty list in proxy processor.

Hope that helps. Sorry again for the late response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants