Skip to content

Conversation

@rakshith91
Copy link
Contributor

@rakshith91 rakshith91 commented Jun 23, 2021

Fixes #19410

Background:
@jongio's code tried sending EG event schema to cloud event's from_dict method which won't work. Need to imrpove the error message here.

@ghost ghost added the Azure.Core label Jun 23, 2021
:type event: dict
:rtype: CloudEvent
"""
if not all([_ in event for _ in ("source", "type")]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the description of the doc or a link?

Copy link
Contributor Author

@rakshith91 rakshith91 Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

kwargs = {} # type: Dict[Any, Any]
reserved_attr = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these keys case-sensitive?

Copy link
Contributor Author

@rakshith91 rakshith91 Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - making it non case sensitive would be breaking

if all([_ in event for _ in ("subject", "eventType", "data", "dataVersion", "id", "eventTime")]):
raise ValueError(
"The event does not conform to the cloud event spec https://github.com/cloudevents/spec." +
" Try using the EventGridEvent from azure-eventgrid library"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be more explicit:
It looks like your event is an EventGrid schema. You can parse EventGrid events using EventGridEvent.from_dict of the azure-eventgrid library

"The event does not conform to the cloud event spec https://github.com/cloudevents/spec." +
" Try using the EventGridEvent from azure-eventgrid library"
)
raise ValueError(
Copy link
Member

@lmazuel lmazuel Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do this whole block into a try/except around the cls at the end, pure EAFP

@rakshith91 rakshith91 merged commit 5efa87d into Azure:main Jun 28, 2021
iscai-msft added a commit that referenced this pull request Jun 28, 2021
…into rest_layer

* 'main' of https://github.com/Azure/azure-sdk-for-python:
  modify _on to _time (#19546)
  Improved error message in the `from_dict` (#19416)
  Regenerate code with latest commit (#19512)
  [auto-release-pipeline] update auto-calculation rule for version number (#19488)
  fix dependencies (#19513)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CloudEvent should throw a proper message when sent wrong event schema

3 participants