Skip to content

Commit

Permalink
Fix adal error when exception doesn't return Response with json (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
akharit authored Sep 14, 2020
1 parent 21d7d6e commit c5557ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.0.50 (2020-09-10)
+++++++++++++++++++
* Fix bug with retrying for ADAL exception parsing.

0.0.49 (2020-08-05)
+++++++++++++++++++
* Fix bug with NoRetryPolicy
Expand Down
2 changes: 1 addition & 1 deletion azure/datalake/store/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# license information.
# --------------------------------------------------------------------------

__version__ = "0.0.49"
__version__ = "0.0.50"

from .core import AzureDLFileSystem
from .multithread import ADLDownloader
Expand Down
26 changes: 12 additions & 14 deletions azure/datalake/store/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ def f_retry(*args, **kwargs):
# ADAL error corresponds to everything but 429, which bubbles up HTTP error.
last_exception = e
logger.exception("Retry count " + str(retry_count) + "Exception :" + str(last_exception))

if hasattr(last_exception, 'error_response'): # ADAL exception
response = response_from_adal_exception(last_exception)
if hasattr(last_exception, 'response'): # HTTP exception i.e 429
response = last_exception.response

# We don't want to stop retry for any error in parsing the exception. This is a GET operation.
try:
if hasattr(last_exception, 'error_response'): # ADAL exception
response = response_from_adal_exception(last_exception)
if hasattr(last_exception, 'response'): # HTTP exception i.e 429
response = last_exception.response
except:
pass
request_successful = last_exception is None or (response is not None and response.status_code == 401) # 401 = Invalid credentials
if request_successful or not retry_policy.should_retry(response, last_exception, retry_count):
break
Expand All @@ -116,15 +118,11 @@ def response_from_adal_exception(e):
import re
from collections import namedtuple

response = e.error_response
http_code = re.search("http error: (\d+)", str(e))
http_code = re.search(r"http error: (\d+)", str(e))
if http_code is not None: # Add status_code to response object for use in should_retry
keys = list(response.keys()) + ['status_code']
status_code = int(http_code.group(1))
values = list(response.values()) + [status_code]

Response = namedtuple("Response", keys)
status_code = [int(http_code.group(1))]
Response = namedtuple("Response", ['status_code'])
response = Response(
*values) # Construct response object with adal exception response and http code
*status_code) # Construct response object with adal exception response and http code
return response

0 comments on commit c5557ec

Please sign in to comment.