diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index 1b270c226a0f..b8043e1e9345 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -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 diff --git a/sdk/core/azure-core/azure/core/pipeline/policies/_universal.py b/sdk/core/azure-core/azure/core/pipeline/policies/_universal.py index 178db95a7dd7..f329dc9914f2 100644 --- a/sdk/core/azure-core/azure/core/pipeline/policies/_universal.py +++ b/sdk/core/azure-core/azure/core/pipeline/policies/_universal.py @@ -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 @@ -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):