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.
Is it possible an IndexError could be raised here?
There was a problem hiding this comment.
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.
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.
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.
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.
m = message.Message(body= b'', body_type=uamqp.MessageBodyType.Data)
for data in m.get_data():
print(data)
>>> b''
This reverts commit f6b6593.
|
/check-enforcer override |
Fixes #19247