azure-sdk-for-python
azure-sdk-for-python copied to clipboard
AppInsights, ARM - getting/creating Annotations causes a deserialization error
Describe the bug
The AppInsights mgmt package has an API for manipulating Annotations.
When creating or getting an Annotation there's a deserialization exception. The annotation does actually get created, so it appears the issue is just in deserializing the response when it has an Annotation.
Exception or Stack Trace
This stack trace is from a .create():
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\dev\azhackery\annotations\bug.py", line 19, in <module>
resp = client.annotations.create(rg, ai_name, annotation_properties=Annotation(
File "C:\dev\azhackery\annotations\lib\site-packages\azure\core\tracing\decorator.py", line 78, in wrapper_use_tracer
return func(*args, **kwargs)
File "C:\dev\azhackery\annotations\lib\site-packages\azure\mgmt\applicationinsights\v2015_05_01\operations\_annotations_operations.py", line 361, in create
deserialized = self._deserialize('[Annotation]', pipeline_response)
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\serialization.py", line 1376, in __call__
return self._deserialize(target_obj, data)
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\serialization.py", line 1415, in _deserialize
return self.deserialize_data(data, response)
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\serialization.py", line 1637, in deserialize_data
raise_with_traceback(DeserializationError, msg, err)
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\exceptions.py", line 51, in raise_with_traceback
raise error.with_traceback(exc_traceback)
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\serialization.py", line 1626, in deserialize_data
return self.deserialize_type[iter_type](data, data_type[1:-1])
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\serialization.py", line 1653, in deserialize_iter
raise DeserializationError("Cannot deserialize as [{}] an object of type {}".format(
azure.core.exceptions.DeserializationError: ("Unable to deserialize response data. Data: {'AnnotationName': 'test-annotation-1', 'Id': 'test-annotation-1', 'Category': 'some-category', 'Properties': None, 'EventTime': '2022-06-21T00:17:11.889599+00:00', 'RelatedAnnotation': 'null'}, [Annotation], DeserializationError: Cannot deserialize as [Annotation] an object of type <class 'dict'>", DeserializationError("Cannot deserialize as [Annotation] an object of type <class 'dict'>"))
To Reproduce
- Create an AppInsights resource
- Install
azure-mgmt-applicationinsights==3.1.0
Here's the code I used:
dac = DefaultAzureCredential()
client = ApplicationInsightsManagementClient(dac, subscriptionId)
resp = client.annotations.create(rg, ai_name, annotation_properties=Annotation(
annotation_name="test-annotation-1",
id="test-annotation-1",
category="some-category",
event_time=datetime.utcnow()
))
# you also get a deserialization failure if you attempt to get the rule as well.
client.annotations.get(rg, ai_name, "test-annotation-1")
The simplest way to check that it was actually created is just attempting to create it again, which yields this (expected) error:
azure.core.exceptions.ResourceExistsError: (Conflict) Annotation with id 'test-annotation-1' already exists
Code: Conflict
Message: Annotation with id 'test-annotation-1' already exists
Inner error: {
"trace": [
"Microsoft.AppInsights.Nexus.ResourceStore.ResourceStoreException"
]
Expected behavior
No exception.
Setup (please complete the following information):
- Python Version: Python 3.10.4
- SDK Version: [e.g. azure-mgmt-applicationinsights 3.1.0]
Thank you for your feedback. This has been routed to the support team for assistance.
Hi @richardpark-msft
According to the issue information you provided, an annotation_name is created first, and then an id is created with the same name as the annotation_name, which will result in Message: Annotation with id 'test-annotation-1' already exists, which cannot be created with the same name
It is recommended that you try to change an id name, so that there should be no similar error messages.
If this does not solve your problem, it is recommended that you submit your issue on rest, because the SDK is generated by swagger.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @azmonapplicationinsights.
Issue Details
Describe the bug
The AppInsights mgmt package has an API for manipulating Annotations.
When creating or getting an Annotation there's a deserialization exception. The annotation does actually get created, so it appears the issue is just in deserializing the response when it has an Annotation.
Exception or Stack Trace
This stack trace is from a .create():
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\dev\azhackery\annotations\bug.py", line 19, in <module>
resp = client.annotations.create(rg, ai_name, annotation_properties=Annotation(
File "C:\dev\azhackery\annotations\lib\site-packages\azure\core\tracing\decorator.py", line 78, in wrapper_use_tracer
return func(*args, **kwargs)
File "C:\dev\azhackery\annotations\lib\site-packages\azure\mgmt\applicationinsights\v2015_05_01\operations\_annotations_operations.py", line 361, in create
deserialized = self._deserialize('[Annotation]', pipeline_response)
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\serialization.py", line 1376, in __call__
return self._deserialize(target_obj, data)
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\serialization.py", line 1415, in _deserialize
return self.deserialize_data(data, response)
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\serialization.py", line 1637, in deserialize_data
raise_with_traceback(DeserializationError, msg, err)
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\exceptions.py", line 51, in raise_with_traceback
raise error.with_traceback(exc_traceback)
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\serialization.py", line 1626, in deserialize_data
return self.deserialize_type[iter_type](data, data_type[1:-1])
File "C:\dev\azhackery\annotations\lib\site-packages\msrest\serialization.py", line 1653, in deserialize_iter
raise DeserializationError("Cannot deserialize as [{}] an object of type {}".format(
azure.core.exceptions.DeserializationError: ("Unable to deserialize response data. Data: {'AnnotationName': 'test-annotation-1', 'Id': 'test-annotation-1', 'Category': 'some-category', 'Properties': None, 'EventTime': '2022-06-21T00:17:11.889599+00:00', 'RelatedAnnotation': 'null'}, [Annotation], DeserializationError: Cannot deserialize as [Annotation] an object of type <class 'dict'>", DeserializationError("Cannot deserialize as [Annotation] an object of type <class 'dict'>"))
To Reproduce
- Create an AppInsights resource
- Install
azure-mgmt-applicationinsights==3.1.0
Here's the code I used:
dac = DefaultAzureCredential()
client = ApplicationInsightsManagementClient(dac, subscriptionId)
resp = client.annotations.create(rg, ai_name, annotation_properties=Annotation(
annotation_name="test-annotation-1",
id="test-annotation-1",
category="some-category",
event_time=datetime.utcnow()
))
# you also get a deserialization failure if you attempt to get the rule as well.
client.annotations.get(rg, ai_name, "test-annotation-1")
The simplest way to check that it was actually created is just attempting to create it again, which yields this (expected) error:
azure.core.exceptions.ResourceExistsError: (Conflict) Annotation with id 'test-annotation-1' already exists
Code: Conflict
Message: Annotation with id 'test-annotation-1' already exists
Inner error: {
"trace": [
"Microsoft.AppInsights.Nexus.ResourceStore.ResourceStoreException"
]
Expected behavior
No exception.
Setup (please complete the following information):
- Python Version: Python 3.10.4
- SDK Version: [e.g. azure-mgmt-applicationinsights 3.1.0]
| Author: | richardpark-msft |
|---|---|
| Assignees: | msyyc |
| Labels: |
|
| Milestone: | - |
Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!
@Wzb123456789 - the 'annotation already exists' problem isn't actually the problem. I only included that to make it clear that the call to create the annotation worked so the exception that happens must be happening because it can't deserialize the response.
The root problem is this one:
azure.core.exceptions.DeserializationError: ("Unable to deserialize response data. Data: {'AnnotationName': 'test-annotation-1', 'Id': 'test-annotation-1', 'Category': 'some-category', 'Properties': None, 'EventTime': '2022-06-21T00:17:11.889599+00:00', 'RelatedAnnotation': 'null'}, [Annotation], DeserializationError: Cannot deserialize as [Annotation] an object of type <class 'dict'>", DeserializationError("Cannot deserialize as [Annotation] an object of type <class 'dict'>"))
And more specifically:
DeserializationError("Cannot deserialize as [Annotation] an object of type <class 'dict'>"))
Which seems to indicate a mismatch, in the code for .create(), between what actually gets returned from the service and what we are deserializing.
Hi @richardpark-msft
Regarding this issue, since the .create() function you are using is an old version, it is recommended that you use the .create_or_update() function to try again, because this function is compatible with the latest azure.mgmt.applicationinsights version.
fyi: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/applicationinsights/azure-mgmt-applicationinsights/azure/mgmt/applicationinsights/v2022_04_01/operations/_workbooks_operations.py#L694
Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!
I'll take a look, it's been awhile since I've looked at it. Just regenerating the package might have been enough since it appeared to just be a data contract mismatch.
Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!