-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed
Labels
Azure.CorebugThis issue requires a change to an existing behavior in the product in order to be resolved.This issue requires a change to an existing behavior in the product in order to be resolved.
Description
_SansIOHTTPPolicyRunner allows a SansIOHTTPPolicy to stop it propagating pipeline exceptions, by returning True from its on_exception method. However, when a policy does this, _SansIOHTTPPolicyRunner raises UnboundLocalError:
from azure.core.pipeline import Pipeline
from azure.core.pipeline.transport import HttpRequest
from azure.core.pipeline.policies import HTTPPolicy, SansIOHTTPPolicy
class ReproPolicy(SansIOHTTPPolicy):
def on_exception(self, request):
return True
class ErrorPolicy(HTTPPolicy):
def send(self, request):
raise Exception("oops")
pipeline = Pipeline(transport=object(), policies=[ReproPolicy(), ErrorPolicy()])
pipeline.run(HttpRequest("GET", "..."))Traceback (most recent call last):
...
File "c:\code\azure-sdk-for-python\sdk\core\azure-core\azure\core\pipeline\_base.py", line 77, in send
return response
UnboundLocalError: local variable 'response' referenced before assignment
... which makes sense because an exception prevents the assignment:
azure-sdk-for-python/sdk/core/azure-core/azure/core/pipeline/_base.py
Lines 70 to 77 in 82175dc
| try: | |
| response = self.next.send(request) | |
| except Exception: # pylint: disable=broad-except | |
| if not _await_result(self._policy.on_exception, request): | |
| raise | |
| else: | |
| _await_result(self._policy.on_response, request, response) | |
| return response |
I opened an issue rather than a PR because the fix requires some design. Should _SansIOHTTPPolicyRunner return a PipelineResponse with no http_response in this case?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Azure.CorebugThis issue requires a change to an existing behavior in the product in order to be resolved.This issue requires a change to an existing behavior in the product in order to be resolved.