-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Improved error message in the from_dict
#19416
Changes from 4 commits
2b8283e
e3fc8e6
f09c3c8
18b3999
1cc83d9
3091e9c
53660ec
b43d1a3
10d2d0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,19 @@ def from_dict(cls, event): | |
:type event: dict | ||
:rtype: CloudEvent | ||
""" | ||
# https://github.com/cloudevents/spec Cloud event spec requires source, type, | ||
# specversion. We autopopulate everything other than source, type. | ||
if not all([_ in event for _ in ("source", "type")]): | ||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be more explicit: |
||
) | ||
raise ValueError( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would do this whole block into a try/except around the |
||
"The event does not conform to the cloud event spec https://github.com/cloudevents/spec." + | ||
" source and type are required." | ||
) | ||
|
||
kwargs = {} # type: Dict[Any, Any] | ||
reserved_attr = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these keys case-sensitive? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes - making it non case sensitive would be breaking |
||
"data", | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added https://github.com/cloudevents/spec