Skip to content

Commit ae746f1

Browse files
committed
Fix bug caching requests with request_hooks
1 parent 25c4840 commit ae746f1

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

astroquery/query.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,22 @@
3030
__all__ = ['BaseVOQuery', 'BaseQuery', 'QueryWithLogin']
3131

3232

33-
def to_cache(response, cache_file):
33+
def to_cache(original_response, cache_file):
3434
log.debug("Caching data to {0}".format(cache_file))
3535

36-
response = copy.deepcopy(response)
37-
if hasattr(response, 'request'):
38-
for key in tuple(response.request.hooks.keys()):
39-
del response.request.hooks[key]
36+
hooks = None
37+
if hasattr(original_response, 'request'):
38+
hooks = original_response.request.hooks
39+
del original_response.request.hooks
40+
if hasattr(original_response, 'history'):
41+
for r in original_response.history:
42+
if hasattr(r, 'request'):
43+
del r.request.hooks
44+
response_copy = copy.deepcopy(original_response)
45+
if hooks:
46+
original_response.request.hooks = hooks
4047
with open(cache_file, "wb") as f:
41-
pickle.dump(response, f, protocol=4)
48+
pickle.dump(response_copy, f, protocol=4)
4249

4350

4451
def _replace_none_iterable(iterable):

0 commit comments

Comments
 (0)