astropy / astropy/astroquery

JPL SBDB query sometimes fails when ``alternate_id=True``

Open
#1,541 6 comments 0 reactions 0 assignees View on GitHub
jplsbdb
Dominant language
Python
Stars
791
Forks
451
Avg merge
1d 3h
Merged PRs (30d)
4

Description

While testing for random asteroids, I found KeyError happens for few cases when ``alternate_id=True`` (if I turn this off, it works fine for my test cases).

Sample code:
```python
from astroquery.jplsbdb import SBDB
obj = SBDB.query('331471', phys=True, alternate_id=True)
```
Error:
```
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
in
----> 1 obj = SBDB.query('331471', phys=True, alternate_id=True)
2 obj

~/anaconda3/lib/python3.7/site-packages/astroquery-0.3.10.dev5703-py3.7.egg/astroquery/utils/class_or_instance.py in f(*args, **kwds)
23 def f(*args, **kwds):
24 if obj is not None:
---> 25 return self.fn(obj, *args, **kwds)
26 else:
27 return self.fn(cls, *args, **kwds)

~/anaconda3/lib/python3.7/site-packages/astroquery-0.3.10.dev5703-py3.7.egg/astroquery/utils/process_asyncs.py in newmethod(self, *args, **kwargs)
27 if kwargs.get('get_query_payload') or kwargs.get('field_help'):
28 return response
---> 29 result = self._parse_result(response, verbose=verbose)
30 self.table = result
31 return result

~/anaconda3/lib/python3.7/site-packages/astroquery-0.3.10.dev5703-py3.7.egg/astroquery/jplsbdb/core.py in _parse_result(self, response, verbose)
205 raise ValueError(src['message'] + ' ({:s})'.format(src['code']))
206
--> 207 src = self._process_data(src)
208
209 # add query uri, if desired

~/anaconda3/lib/python3.7/site-packages/astroquery-0.3.10.dev5703-py3.7.egg/astroquery/jplsbdb/core.py in _process_data(self, src)
314 # re-run this function on leaf dicts
315 elif isinstance(val, dict):
--> 316 res[key] = self._process_data(val)
317
318 # use leaf scalars (and apply units, where applicable)

~/anaconda3/lib/python3.7/site-packages/astroquery-0.3.10.dev5703-py3.7.egg/astroquery/jplsbdb/core.py in _process_data(self, src)
267 # try to convert list of strings to array
268 for i in range(len(val)):
--> 269 if isinstance(val[i][field], bytes):
270 val[i][field] = val[i][field].decode(
271 'utf-8')

KeyError: 'des'
```

As seen in the error lines, I used python 3.7 and astroquery 0.3.10.dev5703.

Contributor guide

Open the contributing guide

Research direction

Reproduce the sample SBDB.query('331471', phys=True, alternate_id=True) call, then start in astroquery/jplsbdb/core.py at _parse_result and _process_data, where the traceback shows the KeyError. Trace how alternate identifiers are processed for this response. Done means the sample query succeeds with alternate_id=True without raising KeyError, while the existing behavior remains intact when it is false.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.