Skip to content

Commit c04be3e

Browse files
committed
fix for issue 2139: add an ability to remove the cache file if a failed
query occurs (the query succeeded but was unparseable)
1 parent c29328b commit c04be3e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

astroquery/query.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ def from_cache(self, cache_location):
115115
log.debug("Retrieving data from {0}".format(request_file))
116116
return response
117117

118+
def remove_cache_file(self, cache_location):
119+
"""
120+
Remove the cache file - may be needed if a query fails during parsing
121+
(successful request, but failed return)
122+
"""
123+
request_file = self.request_file(cache_location)
124+
125+
if os.path.exists(request_file):
126+
os.remove(request_file)
127+
else:
128+
raise OSError(f"Tried to remove cache file {request_file} but "
129+
"it does not exist")
130+
131+
118132

119133
class LoginABCMeta(abc.ABCMeta):
120134
"""

astroquery/simbad/core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ def query_objectids(self, object_name, verbose=False, cache=True,
928928
return self._parse_result(response, SimbadObjectIDsResult,
929929
verbose=verbose)
930930

931+
931932
def query_objectids_async(self, object_name, cache=True,
932933
get_query_payload=False):
933934
"""
@@ -1055,6 +1056,12 @@ def _parse_result(self, result, resultclass=SimbadVOTableResult,
10551056
return None
10561057
except Exception as ex:
10571058
self.last_table_parse_error = ex
1059+
try:
1060+
self._last_query.remove_cache_file(self.cache_location)
1061+
except OSError:
1062+
# this is allowed: if `cache` was set to False, this
1063+
# won't be needed
1064+
pass
10581065
raise TableParseError("Failed to parse SIMBAD result! The raw "
10591066
"response can be found in "
10601067
"self.last_response, and the error in "

0 commit comments

Comments
 (0)