Skip to content
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

Merged
merged 23 commits into from
Aug 4, 2021

Conversation

rakshith91
Copy link
Contributor

@rakshith91 rakshith91 commented Jul 23, 2021

Fixes #19247

@rakshith91 rakshith91 marked this pull request as ready for review July 27, 2021 16:29
@rakshith91 rakshith91 changed the title Draft for magic events CloudEvents/EG Events must recognize magic events Jul 27, 2021
sdk/core/azure-core/CHANGELOG.md Outdated Show resolved Hide resolved
sdk/core/azure-core/azure/core/messaging.py Outdated Show resolved Hide resolved
sdk/core/azure-core/azure/core/messaging.py Outdated Show resolved Hide resolved
sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py Outdated Show resolved Hide resolved
# eventhubs
try:
return json.loads(next(obj.body))[0]
except KeyError:
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

@rakshith91 rakshith91 Aug 2, 2021

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.

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

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/core/azure-core/azure/core/messaging.py Outdated Show resolved Hide resolved
@rakshith91
Copy link
Contributor Author

/check-enforcer override

@rakshith91 rakshith91 merged commit acf2264 into Azure:main Aug 4, 2021
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 magically recognize dict's from known services
2 participants