Skip to content

Commit e500566

Browse files
authored
Merge pull request #2253 from mkelley/jplhorizons-failed-query-cache
Fix for issue #2237: do not cache results that cannot be parsed.
2 parents 501e1dd + 55d6619 commit e500566

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

astroquery/jplhorizons/core.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,11 +1287,20 @@ def _parse_result(self, response, verbose=None):
12871287
data : `astropy.Table`
12881288
12891289
"""
1290+
self.last_response = response
12901291
if self.query_type not in ['ephemerides', 'elements', 'vectors']:
12911292
return None
12921293
else:
1293-
data = self._parse_horizons(response.text)
1294-
1294+
try:
1295+
data = self._parse_horizons(response.text)
1296+
except Exception as ex:
1297+
try:
1298+
self._last_query.remove_cache_file(self.cache_location)
1299+
except OSError:
1300+
# this is allowed: if `cache` was set to False, this
1301+
# won't be needed
1302+
pass
1303+
raise
12951304
return data
12961305

12971306

astroquery/jplhorizons/tests/data/README

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ ceres_vectors.txt
1010
https://ssd.jpl.nasa.gov/api/horizons.api?format=text&EPHEM_TYPE=VECTORS&OUT_UNITS=AU-D&COMMAND=%22Ceres%3B%22&CENTER=%27500%4010%27&CSV_FORMAT=%22YES%22&REF_PLANE=ECLIPTIC&REF_SYSTEM=ICRF&TP_TYPE=ABSOLUTE&VEC_LABELS=YES&VEC_CORR=%22NONE%22&VEC_DELTA_T=NO&OBJ_DATA=YES&TLIST=2451544.5
1111

1212
no_H.txt
13-
https://ssd.jpl.nasa.gov/api/horizons.api?format=text&EPHEM_TYPE=OBSERVER&QUANTITIES=%271%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%2C11%2C12%2C13%2C14%2C15%2C16%2C17%2C18%2C19%2C20%2C21%2C22%2C23%2C24%2C25%2C26%2C27%2C28%2C29%2C30%2C31%2C32%2C33%2C34%2C35%2C36%2C37%2C38%2C39%2C40%2C41%2C42%2C43%27&COMMAND=%221935+UZ%3B%22&SOLAR_ELONG=%220%2C180%22&LHA_CUTOFF=0&CSV_FORMAT=YES&CAL_FORMAT=BOTH&ANG_FORMAT=DEG&APPARENT=AIRLESS&REF_SYSTEM=ICRF&EXTRA_PREC=NO&CENTER=%27500%40399%27&TLIST=2459480.5004416634&SKIP_DAYLT=NO
13+
https://ssd.jpl.nasa.gov/api/horizons.api?format=text&EPHEM_TYPE=OBSERVER&QUANTITIES=%271%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%2C11%2C12%2C13%2C14%2C15%2C16%2C17%2C18%2C19%2C20%2C21%2C22%2C23%2C24%2C25%2C26%2C27%2C28%2C29%2C30%2C31%2C32%2C33%2C34%2C35%2C36%2C37%2C38%2C39%2C40%2C41%2C42%2C43%27&COMMAND=%221935+UZ%3B%22&SOLAR_ELONG=%220%2C180%22&LHA_CUTOFF=0&CSV_FORMAT=YES&CAL_FORMAT=BOTH&ANG_FORMAT=DEG&APPARENT=AIRLESS&REF_SYSTEM=ICRF&EXTRA_PREC=NO&CENTER=%27500%40399%27&TLIST=2459480.5004416634&SKIP_DAYLT=NO
14+
15+
tlist_error.txt
16+
https://ssd.jpl.nasa.gov/api/horizons.api?format=text&COMMAND=%27499%27&OBJ_DATA=%27YES%27&MAKE_EPHEM=%27YES%27&EPHEM_TYPE=%27OBSERVER%27&CENTER=%27500@399%27&QUANTITIES=%271,9,20,23,24,29%27&TLIST=[]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
API VERSION: 1.1
2+
API SOURCE: NASA/JPL Horizons API
3+
4+
BATVAR: no TLIST values found (or missing quotes)
5+
WLDINI: error loading execution-control file.

astroquery/jplhorizons/tests/test_jplhorizons.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22

3+
from multiprocessing import Value
34
import pytest
45
import os
56
from collections import OrderedDict
@@ -9,13 +10,16 @@
910
from astropy.utils.exceptions import AstropyDeprecationWarning
1011

1112
from ...utils.testing_tools import MockResponse
13+
from ...query import AstroQuery
14+
from ...exceptions import TableParseError
1215
from ... import jplhorizons
1316

1417
# files in data/ for different query types
1518
DATA_FILES = {'ephemerides': 'ceres_ephemerides.txt',
1619
'elements': 'ceres_elements.txt',
1720
'vectors': 'ceres_vectors.txt',
18-
'"1935 UZ"': 'no_H.txt'}
21+
'"1935 UZ"': 'no_H.txt',
22+
'"tlist_error"': 'tlist_error.txt'}
1923

2024

2125
def data_path(filename):
@@ -55,6 +59,13 @@ def patch_request(request):
5559

5660
# --------------------------------- actual test functions
5761

62+
def test_parse_result(patch_request):
63+
q = jplhorizons.Horizons(id='tlist_error')
64+
# need _last_query to be defined
65+
q._last_query = AstroQuery('GET', 'http://dummy')
66+
with pytest.raises(ValueError):
67+
res = q.ephemerides()
68+
5869

5970
def test_ephemerides_query(patch_request):
6071
# check values of Ceres for a given epoch

0 commit comments

Comments
 (0)