sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

CloudEvent equality is incorrect on none attributes

Open sasha-tkachev opened this issue 3 years ago • 4 comments

CloudEvent equality is incorrect on none attributes

from cloudevents.http import CloudEvent
CloudEvent(attributes={"type": "a", "source": "a", "a": None}) == CloudEvent({"type": "a", "source":"a"})

expected True

actual False

the spec says that null value attributes are the same as non-existing attributes

sasha-tkachev avatar Nov 09 '22 14:11 sasha-tkachev

Can you please point to a specific place where this is stated in the spec? I have a pretty hard time finding this in the spec.

xSAVIKx avatar Nov 09 '22 18:11 xSAVIKx

It is specified only in the JSON format type system mapping I even think we MUST NOT allow None values for attributes. Because it is not a supported attribute type

sasha-tkachev avatar Nov 11 '22 09:11 sasha-tkachev

Unset attributes MAY be encoded to the JSON value of null

So looks like None is a valid input.

Also, we're talking about JSON representation of the event, not about language-specific representation. IMO, it means that to_json(CloudEvent(attributes={"type": "a", "source": "a", "a": None})) must be == to to_json(CloudEvent({"type": "a", "source":"a"})). But it does not require CloudEvent instances to be equal.

xSAVIKx avatar Nov 11 '22 10:11 xSAVIKx

Or actually:

from_json(to_json(CloudEvent(attributes={"type": "a", "source": "a", "a": None}))) must be == to from_json(to_json(CloudEvent({"type": "a", "source":"a"})))

So we must be treating JSON representation with null or without a value in the very same way. But it is not required for the instance of CloudEvent.

xSAVIKx avatar Nov 11 '22 10:11 xSAVIKx