-
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
Conversation
@@ -122,6 +122,16 @@ def from_dict(cls, event): | |||
:type event: dict | |||
:rtype: CloudEvent | |||
""" | |||
if not all([_ in event for _ in ("source", "type")]): |
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.
raise ValueError( | ||
"The event does not conform to the cloud event 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 comment
The 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 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" |
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.
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( |
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.
I would do this whole block into a try/except around the cls
at the end, pure EAFP
…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)
* Improved error message in the `from_dict` * lint * spec lin * tests * Add AAD support * eafp * Revert "Add AAD support" This reverts commit 1cc83d9. * language * lint
[OperationalInsights] workspace and component purge (Azure#19416) * Add blockchain to latest profile * Add additional types * Purge update * bad syntax fix for workspacePurge examples * pretty Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
[OperationalInsights] workspace and component purge (Azure#19416) * Add blockchain to latest profile * Add additional types * Purge update * bad syntax fix for workspacePurge examples * pretty Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
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.