Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #2237: do not cache results that cannot be parsed. #2253

Merged
merged 2 commits into from
Dec 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions astroquery/jplhorizons/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,11 +1287,20 @@ def _parse_result(self, response, verbose=None):
data : `astropy.Table`

"""
self.last_response = response
if self.query_type not in ['ephemerides', 'elements', 'vectors']:
return None
else:
data = self._parse_horizons(response.text)

try:
data = self._parse_horizons(response.text)
except Exception as ex:
try:
self._last_query.remove_cache_file(self.cache_location)
except OSError:
# this is allowed: if `cache` was set to False, this
# won't be needed
pass
raise
return data


Expand Down
5 changes: 4 additions & 1 deletion astroquery/jplhorizons/tests/data/README
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ ceres_vectors.txt
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

no_H.txt
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
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

tlist_error.txt
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=[]
5 changes: 5 additions & 0 deletions astroquery/jplhorizons/tests/data/tlist_error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
API VERSION: 1.1
API SOURCE: NASA/JPL Horizons API

BATVAR: no TLIST values found (or missing quotes)
WLDINI: error loading execution-control file.
13 changes: 12 additions & 1 deletion astroquery/jplhorizons/tests/test_jplhorizons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from multiprocessing import Value
import pytest
import os
from collections import OrderedDict
Expand All @@ -9,13 +10,16 @@
from astropy.utils.exceptions import AstropyDeprecationWarning

from ...utils.testing_tools import MockResponse
from ...query import AstroQuery
from ...exceptions import TableParseError
from ... import jplhorizons

# files in data/ for different query types
DATA_FILES = {'ephemerides': 'ceres_ephemerides.txt',
'elements': 'ceres_elements.txt',
'vectors': 'ceres_vectors.txt',
'"1935 UZ"': 'no_H.txt'}
'"1935 UZ"': 'no_H.txt',
'"tlist_error"': 'tlist_error.txt'}


def data_path(filename):
Expand Down Expand Up @@ -55,6 +59,13 @@ def patch_request(request):

# --------------------------------- actual test functions

def test_parse_result(patch_request):
q = jplhorizons.Horizons(id='tlist_error')
# need _last_query to be defined
q._last_query = AstroQuery('GET', 'http://dummy')
with pytest.raises(ValueError):
res = q.ephemerides()


def test_ephemerides_query(patch_request):
# check values of Ceres for a given epoch
Expand Down