Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bugs Fixed

- respect text encoding specified in argument (thanks to @ryohji for the contribution) #20796
- Fix "coroutine x.read() was never awaited" warning from `ContentDecodePolicy` #21318
- fix type check for `data` input to `azure.core.rest` for python 2.7 users #21341

### Other Changes
Expand Down
16 changes: 12 additions & 4 deletions sdk/core/azure-core/azure/core/pipeline/policies/_universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"""
from __future__ import absolute_import # we have a "requests" module that conflicts with "requests" on Py2.7
import json
import inspect
import logging
import os
import platform
Expand Down Expand Up @@ -618,10 +619,17 @@ def deserialize_from_http_generics(

# Rely on transport implementation to give me "text()" decoded correctly
if hasattr(response, "read"):
# since users can call deserialize_from_http_generics by themselves
# we want to make sure our new responses are read before we try to
# deserialize
response.read()
try:
# since users can call deserialize_from_http_generics by themselves
# we want to make sure our new responses are read before we try to
# deserialize. Only read sync responses since we're in a sync function
if not inspect.iscoroutinefunction(response.read):
response.read()
except AttributeError:
# raises an AttributeError in 2.7 bc inspect.iscoroutinefunction was added in 3.5
# Entering here means it's 2.7 and that the response has a read method, so we read
# bc it will be sync.
response.read()
return cls.deserialize_from_text(response.text(encoding), mime_type, response=response)

def on_request(self, request):
Expand Down