json-rpc
json-rpc copied to clipboard
Consider accepting params=None for JSON-RPC 1.0
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)
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.