-
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
CloudEvents/EG Events must recognize magic events #19922
Conversation
# eventhubs | ||
try: | ||
return json.loads(next(obj.body))[0] | ||
except KeyError: |
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.
Is it possible an IndexError could be raised here?
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.
And in what case would it raise a KeyError?
Do we also need different handling for a StopIteration error? In that scenario, it meant that we had been passed the right object, but the payload was not valid - so I would expect that to then raise a ValueError, no?
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.
Is it possible an IndexError could be raised here?
I cannot think of a scenario which could raise IndexError, and in case it is, we still return the object as is - and i have tried sending events to EH in diffferent formats - it always returns a "list"
And in what case would it raise a KeyError?
A keyerror is raised when we try to subscript a SB message with 0. essentially, service bus message is a dict. which is fetched by json.loads(next(obj.body))
. So doing a json.loads(next(obj.body))[0]
will give you a key error.
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.
Do we also need different handling for a StopIteration error
No - uamqp does't throw stop iteration https://github.com/Azure/azure-uamqp-python/blob/master/uamqp/message.py#L1159-L1162
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.
Interesting - so if the Event body is an empty list - calling next
on it doesn't raise? What does it do?
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.
m = message.Message(body= b'', body_type=uamqp.MessageBodyType.Data)
for data in m.get_data():
print(data)
>>> b''
sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_eventhub.py
Outdated
Show resolved
Hide resolved
This reverts commit f6b6593.
/check-enforcer override |
Fixes #19247