Skip to content

Commit c5557ec

Browse files
authored
Fix adal error when exception doesn't return Response with json (#316)
1 parent 21d7d6e commit c5557ec

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Release History
44
===============
55

6+
0.0.50 (2020-09-10)
7+
+++++++++++++++++++
8+
* Fix bug with retrying for ADAL exception parsing.
9+
610
0.0.49 (2020-08-05)
711
+++++++++++++++++++
812
* Fix bug with NoRetryPolicy

azure/datalake/store/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# license information.
77
# --------------------------------------------------------------------------
88

9-
__version__ = "0.0.49"
9+
__version__ = "0.0.50"
1010

1111
from .core import AzureDLFileSystem
1212
from .multithread import ADLDownloader

azure/datalake/store/retry.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ def f_retry(*args, **kwargs):
9595
# ADAL error corresponds to everything but 429, which bubbles up HTTP error.
9696
last_exception = e
9797
logger.exception("Retry count " + str(retry_count) + "Exception :" + str(last_exception))
98-
99-
if hasattr(last_exception, 'error_response'): # ADAL exception
100-
response = response_from_adal_exception(last_exception)
101-
if hasattr(last_exception, 'response'): # HTTP exception i.e 429
102-
response = last_exception.response
103-
98+
# We don't want to stop retry for any error in parsing the exception. This is a GET operation.
99+
try:
100+
if hasattr(last_exception, 'error_response'): # ADAL exception
101+
response = response_from_adal_exception(last_exception)
102+
if hasattr(last_exception, 'response'): # HTTP exception i.e 429
103+
response = last_exception.response
104+
except:
105+
pass
104106
request_successful = last_exception is None or (response is not None and response.status_code == 401) # 401 = Invalid credentials
105107
if request_successful or not retry_policy.should_retry(response, last_exception, retry_count):
106108
break
@@ -116,15 +118,11 @@ def response_from_adal_exception(e):
116118
import re
117119
from collections import namedtuple
118120

119-
response = e.error_response
120-
http_code = re.search("http error: (\d+)", str(e))
121+
http_code = re.search(r"http error: (\d+)", str(e))
121122
if http_code is not None: # Add status_code to response object for use in should_retry
122-
keys = list(response.keys()) + ['status_code']
123-
status_code = int(http_code.group(1))
124-
values = list(response.values()) + [status_code]
125-
126-
Response = namedtuple("Response", keys)
123+
status_code = [int(http_code.group(1))]
124+
Response = namedtuple("Response", ['status_code'])
127125
response = Response(
128-
*values) # Construct response object with adal exception response and http code
126+
*status_code) # Construct response object with adal exception response and http code
129127
return response
130128

0 commit comments

Comments
 (0)