Skip to content

Encoded JSON data is not set correctly inside data field #185

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

Closed
sasha-tkachev opened this issue Jul 18, 2022 · 2 comments
Closed

Encoded JSON data is not set correctly inside data field #185

sasha-tkachev opened this issue Jul 18, 2022 · 2 comments
Labels
/spec-v2 Smth that is related to the next major version of the CloudEvents spec wontfix This will not be worked on

Comments

@sasha-tkachev
Copy link
Contributor

sasha-tkachev commented Jul 18, 2022

Expected Behavior

JSON format spec section [#3.1.1] states

If the datacontenttype declares the data to contain JSON-formatted content, a JSON serializer MUST translate the data value to a JSON value, and use the member name data to store it inside the JSON representation. The data value MUST be stored directly as a JSON value, rather than as an encoded JSON document represented as a string.

from cloudevents.http import CloudEvent, to_json
import json
json.loads(
     to_json(
         CloudEvent(
             attributes={"type": "my-type", "source": "my-source"},
             data='{"a": "b"}',
         )
     )
 )["data"] =={"a": "b"}

Actual Behavior

When an encoded json value is passed into the cloud even, when to_json is invoked the resulting json object has an encoded json object in the data field and not a JSON representation as required.

from cloudevents.http import CloudEvent, to_json
import json
json.loads(
     to_json(
         CloudEvent(
             attributes={"type": "my-type", "source": "my-source"},
             data='{"a": "b"}',
         )
     )
 )["data"] == '{"a": "b"}' 

Specifications

  • Platform: windows
  • Python Version: python 3.8

#3.1.1

@xSAVIKx
Copy link
Member

xSAVIKx commented Jul 19, 2022

Hey @sasha-tkachev. Thx for opening the issue.

Although, I'm not sure this is actually an issue. Can you please verify how Event behaves? CloudEvent class as noted is a Python-friendly wrapper and thus is not obliged to follow the spec and may have different behavior.

There's also an open issue in the spec itself that I believe is related to the behavior you're showcasing: cloudevents/spec#558.

@xSAVIKx xSAVIKx added wontfix This will not be worked on /spec-v2 Smth that is related to the next major version of the CloudEvents spec labels Jul 24, 2022
@sasha-tkachev
Copy link
Contributor Author

Ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
/spec-v2 Smth that is related to the next major version of the CloudEvents spec wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants