Event Grid sample code incorrect
anthonychu opened this issue · comments
Reviewing a support case (120021922002942), customer used the sample code here:
https://github.com/MicrosoftDocs/azure-docs-sdk-python/blob/024402b/docs-ref-services/event-grid.md#example
Looks like the events
arguments are passed as a list of dicts and publish_events()
serializes them into an azure.eventgrid.models.EventGridEvent
s, which uses custom serialization. The serialization expects properties in camelCase instead of snack_case. So the sample should be changed to something like:
events=[{
'id' : "dbf93d79-3859-4cac-8055-51e3b6b54bea",
'subject' : "Sample subject",
'data': {
'key': 'Sample Data'
},
'eventType': 'SampleEventType',
'eventTime': datetime(2018, 5, 2),
'dataVersion': 1
}]
Another option that might make more sense is to pass actual EventGridEvent
objects in the list.
We are currently working on a V2 of eventgrid for Python, which will simplify a lot this story (ETA: March), we'll make sure this issue is adressed for the V2.
Thanks!
@anthonychu Thanks for reporting.
We now have a V2 of eventgrid library with enhanced features, updated samples
Please take a look at https://pypi.org/project/azure-eventgrid/
You can get started with the migration guide here https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/migration_guide.md
Closing this issue - but feel free to open another one if you come across any issues in our latest version