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

Invalid JSON: Unexpected type for Value message when passing tuples in json_data #1527

Closed
taavi-primer opened this issue Mar 10, 2020 · 3 comments
Labels
bug triage Needs to be triaged and prioritised accordingly

Comments

@taavi-primer
Copy link
Contributor

Seems SeldonClient is not able to encode tuples when they are passed in through json_data parameter. It is also unclear how to make use of the str_data and data input parameters (those could use documentation).

Small example:

import json
from seldon_core.seldon_client import SeldonClient

seldon_client = SeldonClient(
    gateway="istio",
    transport="rest",
    namespace="ml-serving",
    deployment_name="our-model",
    gateway_endpoint="our-istiogw",
)

example1 = ["Some text here.", "SomeName", [(0, 5)], [(10, 15)]]
example2 = json.loads(json.dumps(example1)) 

try:
    resp = seldon_client.predict(json_data=list([example1]), http_path="/api/v0.1/predictions")
    print(f"Response with example1: {resp.response.data.tensor}")
except Exception as ex:
    print(f"Exception thrown: {str(ex.message)}")

resp = seldon_client.predict(json_data=list([example2]), http_path="/api/v0.1/predictions")
print(f"Response with example2: {resp.response.data.tensor}")

Output from that is:

$ python ~/seldon_example1.py
Exception thrown: Invalid JSON: Unexpected type for Value message.
Response with example2: shape: 1
values: 0.006200790667543826
@taavi-primer taavi-primer added bug triage Needs to be triaged and prioritised accordingly labels Mar 10, 2020
@ukclivecox
Copy link
Contributor

Example1 is not valid JSON. The json module probably handles tuple automatically.

@taavi-primer
Copy link
Contributor Author

How could it be? JSON is a string serialization of an object. Isn't the whole point of the json_data parameter to give it a Python object that needs to be serialized into a string? Or is the expected payload here already JSON-serialized? I don't think the latter works...

@ukclivecox
Copy link
Contributor

The seldon client parses a json method first into a protoBuffer using:

json_format.ParseDict(message_json, message_proto)

So the issue if that it fails at that point due to protoBuffers understanding of what is valid json and a tuple is not valid json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Needs to be triaged and prioritised accordingly
Projects
None yet
Development

No branches or pull requests

2 participants