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

msrest.serialization serializes CloudEvent data field object as string #12831

Closed
t-swpill opened this issue Jul 30, 2020 · 0 comments · Fixed by Azure/msrest-for-python#220
Closed
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Event Grid Messaging Messaging crew

Comments

@t-swpill
Copy link
Contributor

t-swpill commented Jul 30, 2020

I am trying to send a CloudEvent to an Event Grid topic, where CloudEvent is a model which inherits from msrest.serialization.Model. The CloudEvent is the following:

event = CloudEvent(
                type="Azure.Sdk.Sample",
                source="https://egsample.dev/sampleevent",
                data=CustomSample("custom event")
                )

The CustomSample class is:

class CustomSample(msrest.serialization.Model):
    _validation = {
            'a': {'required': True},
    }

    _attribute_map = {
        'a': {'key': 'a', 'type': 'str'},
    }

    def __init__(self, a):
        self.a = a

When the CloudEvent is serialized to send to the Event Grid service, the CustomSample object in the data field is serialized into a string. This means that, when I try to deserialize the CloudEvent again on the receiving side, the data is not deserialized into the original CustomSample object again.

For example, this code:

serialized_event = CloudEvent.serialize(event)
print("serialized: {}".format(serialized_event))
deserialized_event = CloudEvent.deserialize(serialized_event)
print("deserialized: {}".format(deserialized_event))

results in this output:

serialized: {'id': '73cdccf6-e4b0-485f-8965-d27bad36bedc', 'source': 'https://egsample.dev/sampleevent', 'data': "{'a': 'sample event'}", 'type': 'Azure.Sdk.Sample', 'time': '2020-07-30T19:19:39.165385Z', 'specversion': '1.0'}
deserialized: {'additional_properties': None, 'id': '73cdccf6-e4b0-485f-8965-d27bad36bedc', 'data': "{'a': 'sample event'}", 'data_base64': None, 'time': datetime.datetime(2020, 7, 30, 
19, 19, 39, 165385, tzinfo=<isodate.tzinfo.Utc object at 0x000001FF9C64E400>), 'specversion': '1.0', 'dataschema': None, 'datacontenttype': None, 'subject': None, 'source': 'https://egsample.dev/sampleevent', 'type': 'Azure.Sdk.Sample'}

When the value of the data field is set to another type, such as an int or dict, it is serialized/deserialized as an int or dict, respectively. I would similarly expect the data field to be serialized/deserialized as a CustomSample object, instead of a string.

@t-swpill t-swpill added Event Grid Client This issue points to a problem in the data-plane of the library. labels Jul 30, 2020
@lmazuel lmazuel self-assigned this Jul 30, 2020
@lmazuel lmazuel added this to the [2020] September milestone Aug 7, 2020
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-python that referenced this issue Feb 8, 2021
[T2] python track2 config for frontdoor (Azure#12831)

* add python track2 config for frontdoor

* fix
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-python that referenced this issue Feb 8, 2021
[T2] python track2 config for frontdoor (Azure#12831)

* add python track2 config for frontdoor

* fix
00Kai0 added a commit that referenced this issue Feb 9, 2021
* CodeGen from PR 12831 in Azure/azure-rest-api-specs
[T2] python track2 config for frontdoor (#12831)

* add python track2 config for frontdoor

* fix

* test,version,CHANGELOG

* fix changelog and version

Co-authored-by: SDKAuto <sdkautomation@microsoft.com>
@lmazuel lmazuel added the Messaging Messaging crew label Apr 12, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. Event Grid Messaging Messaging crew
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants