Skip to content

Conversation

@alexeldeib
Copy link
Contributor

@alexeldeib alexeldeib commented Jun 17, 2018

This PR has a very similar Query operation group to #2557, which also means that Azure/msrest-for-python#103 (ISO8601 intervals) and Azure/msrest-for-python#104 apply (raw field without transformation).

Azure/azure-rest-api-specs#3257 adds the configuration for auto PRs.

I'm still adding tests, but wanted to begin the review process since the client works nicely 😄

@azuresdkci
Copy link
Contributor

Can one of the admins verify this patch?

@alexeldeib alexeldeib requested a review from lmazuel as a code owner June 17, 2018 22:42
@azuresdkci
Copy link
Contributor

Can one of the admins verify this patch?

@codecov-io
Copy link

codecov-io commented Jun 17, 2018

Codecov Report

Merging #2767 into master will increase coverage by 0.19%.
The diff coverage is 77.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2767      +/-   ##
==========================================
+ Coverage   56.71%   56.91%   +0.19%     
==========================================
  Files        7647     7772     +125     
  Lines      158352   159826    +1474     
==========================================
+ Hits        89803    90958    +1155     
- Misses      68549    68868     +319
Impacted Files Coverage Δ
...applicationinsights/models/events_user_info_py3.py 100% <100%> (ø)
.../models/metrics_post_body_schema_parameters_py3.py 100% <100%> (ø)
azure-applicationinsights/azure/__init__.py 100% <100%> (ø)
...licationinsights/models/metrics_result_info_py3.py 100% <100%> (ø)
.../applicationinsights/models/metrics_result_info.py 100% <100%> (ø)
...re/applicationinsights/models/query_results_py3.py 100% <100%> (ø)
...ghts/models/metrics_post_body_schema_parameters.py 100% <100%> (ø)
...ure/applicationinsights/models/events_user_info.py 100% <100%> (ø)
...licationinsights/models/events_application_info.py 100% <100%> (ø)
...e/applicationinsights/models/events_result_data.py 100% <100%> (ø)
... and 221 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fa8ae2b...0747ab4. Read the comment docs.

@alexeldeib
Copy link
Contributor Author

@lmazuel Does the python SDK support XML deserialization? I see some code for it in ms-rest . I'm seeing however that events_get_odata_metadata (an operation which returns XML), tries to deserialize as JSON.

I also get a log message indicating it's forcing the Accept header to application/json -- figured might be related if the client is expecting JSON.

See test output and relevant swagger lines. I also verified that using 'raw = true', the request is successful and only the deserialization is failing.

@alexeldeib
Copy link
Contributor Author

alexeldeib commented Jun 19, 2018

Better test example, illustrating successful response but failed deserialization

@lmazuel
Copy link
Member

lmazuel commented Jun 20, 2018

@alexeldeib , yes starting autorest.python 3.0.53 and msrest 0.5.0, there is XML support! If the content-type is XML.
I see that you return type is "object", you expect Autorest to return the XML tree? I probably don't have any tests for that. @fearthecowboy @RikkiGibson FYI, what would Autorest Typescript or Autorest core think about this?

@alexeldeib
Copy link
Contributor Author

alexeldeib commented Jun 20, 2018

@lmazuel I think that's accurate as to what I would have expected, or if there's a different way to model it that works with the client otherwise I'd be happy to adjust. This also came up with respect to nodejs -- see Azure/azure-sdk-for-node#3021 (comment) Not decided yet on a solution there

@RikkiGibson
Copy link
Member

I think autorest.typescript will parse the XML and pass it along as a simple object tree, similar to what is returned by JSON.parse(). There will be some special properties to capture things like XML attributes and text content. However I also don't have tests for it so I can't really guarantee what it will do.

@lmazuel
Copy link
Member

lmazuel commented Jun 20, 2018

I think it's fine, it's just I didn't consider this scenario. In all transparency, XML is still pretty new and really vague in the Swagger spec, in particular I didn't find anything about free-form object (what you have) and XML. But I guess it makes sense to return the raw XML tree when we see "object". At least on deserialization, I don't think it can be supported on serialization.
You don't need to declare anything in Python, I base everything on HTTP headers. So if your content-type is XML, you'll get XML deserialization. It might already return you a XML tree, I honestly didn't test that scenario.

Edit: on serialization could be done actually, serializing the tree in place without the <xml> header.

@lmazuel
Copy link
Member

lmazuel commented Jun 22, 2018

@alexeldeib I released a msrest 0.5.1 that should fixes your XML issue. Please confirm when you have some time :)
Thanks!

@alexeldeib
Copy link
Contributor Author

Looks good 😄 I can see the same test fixed in CI build, thanks @lmazuel !

@alexeldeib
Copy link
Contributor Author

alexeldeib commented Jul 12, 2018

@lmazuel hmm, seems like after using latest generation the XML deserialization no longer works? The raw response is still fine, but the object isn't. Was there anything changed here? I didn't see anything obvious that looked problematic in the code myself

@lmazuel
Copy link
Member

lmazuel commented Jul 12, 2018

@alexeldeib I have some deep tests to do on "object" + "additionalProperties", I will double-check this closely, and be sure to add precise test (I did it already, but seems I didn't model your situation close enough :/)

@alexeldeib
Copy link
Contributor Author

alexeldeib commented Jul 12, 2018

@lmazuel I also did some digging into this -- looks like 0.5.1 works, but 0.5.2 breaks. Weird thing is, the parsing works fine when __call__'ed with content-type 'application/xml'.

However, the generated method calls it without a content-type. I'm not sure why this would have worked before, still looking at how to fix. Looking at the diffs i'm not sure how this even broke between 0.5.1 and 0.5.2. The swagger has produces: application/xml, do you have any ideas how to fix the invocation generation here with that additional info?

@lmazuel
Copy link
Member

lmazuel commented Jul 12, 2018

@alexeldeib The generation does not use "content_type", because "response" is a HTTP response object, and the content-type is extracted from the headers.
But the generated code is not using the latest generator, and I have XML fixes in 3.0.53 and 3.0.58, could you regenerate this one with "--use=@microsoft.azure/autorest.python@3.0.58" ?

Edit: looking at your recording:

content-type: [application/xml; charset=utf-8]

this means "content_type" is "application/xml" and is not needed

@lmazuel
Copy link
Member

lmazuel commented Jul 12, 2018

@alexeldeib ok got it, damn....
This test:
Azure/msrest-for-python@1c19601#diff-3ff87e93ca942963e2ffda1097136bfaR1427

if isinstance(data, ET.Element) and not data.text

does not work if it's <root><child/></root> because root has no text....

I'll improve my if statement and add a test for that.

@alexeldeib
Copy link
Contributor Author

Nice catch, I looked at that if statement but thought it was okay 👍 I will also go ahead and push the 3.0.58 generation.

@alexeldeib
Copy link
Contributor Author

I noticed this broke CI and I fixed the corresponding swagger field in this PR. The runtime is doing the right thing, the backend doesn't actually accept these options.

@lmazuel
Copy link
Member

lmazuel commented Jul 12, 2018

Fixed in Azure/msrest-for-python#117

# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json;odata=none'
header_parameters['Accept'] = 'application/json'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is that? Is this an Autorest issue? Something weird in the Swagger?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug in the swagger on my end, see Azure/azure-rest-api-specs#3409

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, saw your comment, thanks!

@lmazuel lmazuel merged commit 4009970 into Azure:master Jul 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants