|
30 | 30 | __all__ = ['BaseVOQuery', 'BaseQuery', 'QueryWithLogin'] |
31 | 31 |
|
32 | 32 |
|
33 | | -def to_cache(response, cache_file): |
| 33 | +def to_cache(original_response, cache_file): |
34 | 34 | log.debug("Caching data to {0}".format(cache_file)) |
35 | 35 |
|
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 | + # Copying a TAPService instance with an auth session produces some warnings |
| 37 | + # as a side affect. The hooks are not needed in the cache, so we remove |
| 38 | + # them before caching and restore them afterwards. |
| 39 | + # Related pyvo issue: https://github.com/astropy/pyvo/issues/755 |
| 40 | + hooks = None |
| 41 | + if hasattr(original_response, 'request'): |
| 42 | + hooks = original_response.request.hooks |
| 43 | + del original_response.request.hooks |
| 44 | + if hasattr(original_response, 'history'): |
| 45 | + for r in original_response.history: |
| 46 | + if hasattr(r, 'request'): |
| 47 | + del r.request.hooks |
| 48 | + response_copy = copy.deepcopy(original_response) |
| 49 | + if hooks: |
| 50 | + original_response.request.hooks = hooks |
40 | 51 | with open(cache_file, "wb") as f: |
41 | | - pickle.dump(response, f, protocol=4) |
| 52 | + pickle.dump(response_copy, f, protocol=4) |
42 | 53 |
|
43 | 54 |
|
44 | 55 | def _replace_none_iterable(iterable): |
|
0 commit comments