Skip to content

Commit 0e21009

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

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

astroquery/query.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,21 @@
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+
if hasattr(original_response, 'request'):
37+
hooks = original_response.request.hooks
38+
del original_response.request.hooks
39+
if hasattr(original_response, 'history'):
40+
for r in original_response.history:
41+
if hasattr(r, 'request'):
42+
del r.request.hooks
43+
response_copy = copy.deepcopy(original_response)
44+
if hooks:
45+
original_response.request.hooks = hooks
4046
with open(cache_file, "wb") as f:
41-
pickle.dump(response, f, protocol=4)
47+
pickle.dump(response_copy, f, protocol=4)
4248

4349

4450
def _replace_none_iterable(iterable):

0 commit comments

Comments
 (0)