L.sherlock_objects skips all data if it doesn't find one

Hi,

I have a list of objects to query but because it doesn’t find one of them skips the whole list. Is there a way to overcome that?

My code is like that:

sp = [ts[x:x+100] for x in range(0, len(ts), 100)]
c = []
for i in sp:
try:
c.append(L.sherlock_objects(i))
except LasairError as e:
print(e)

where ts is a list of 1000 objects so I break it into smaller lists of 100.

Thank you.

Lydia

I tried it on the example notebook, but replacing one of the object Ids with ZTF23_______, and I get: LasairError: Bad Request:{"error":"{"message": "Object ZTF23_______ not found"}}. Do you see this error also? Should we just put a None in the response rather than raising the error and quitting?

Hi,

Thank you for your reply! Yeah, I do get the same error. I will try this solution.

Lydia

Hi @lydiam ! I just wanted to check in about the issue you were having, and whether or not the above post resolved your problem? Thanks!

Apologies for the delay.

I used:

for i in sp:
try:
c.append(L.sherlock_objects(i))
except LasairError as e:
None

instead of print(e) but I still have the same issue.

The real problem here is that the API should behave differently with a list of objects. Instead of falling over when a single object fails, it should return all the successes with NULL or something for the failed one. So I will make this bugfix. (Of course we are working hard on the new Lasair – for LSST – and said to ourselves no messing about with the ZTF code, its supposed to be frozen.)

Thanks for this Roy! Probably I will try a workaround at least for the lists that “fail” by querying each object in this list. Thank you again for all your help!

Hi Lydia – I think its fixed, now just returns None for the missing object. Can you give it a try?

Hi Roy, what is the right way to handle the error in terms of code?

objectIds = ['ZTF17_____etfg', 'ZTF17aaaetet', 'ZTF17aaaetes', 'ZTF17aaaeteo']
rows = L.objects(objectIds)
for (objectId,row) in zip(objectIds,rows):
    if not row:
        print('%s: not found' % objectId)
    else:
        od = row['objectData']
        print('%s is at galactic latlon %.2f,%.3f' % (objectId, od['glatmean'], od['glonmean']))

results in

ZTF17_____etfg: not found
ZTF17aaaetet is at galactic latlon -31.62,129.895
ZTF17aaaetes is at galactic latlon -31.96,129.973
ZTF17aaaeteo is at galactic latlon -31.90,130.475

Hi Roy,

I does indeed work for L.objects but it still fails for L.sherlock_objects. And when trying to do something like:

objectIds = ['ZTF17_____etfg', 'ZTF17aaaetet', 'ZTF17aaaetes', 'ZTF17aaaeteo']
rows = L.objects(objectIds)
for (objectId,row) in zip(objectIds,rows):
    if not row:
        print('%s: not found' % objectId)
    else:
        od = row['objectData']
        print(c.append(L.sherlock_objects(objectId)))
        print('%s is at galactic latlon %.2f,%.3f' % (objectId, od['glatmean'], od['glonmean']))

it returns the following error:

LasairError                               Traceback (most recent call last)
Cell In[32], line 8
      6 else:
      7     od = row['objectData']
----> 8     print(c.append(L.sherlock_objects(objectId)))
      9     print('%s is at galactic latlon %.2f,%.3f' % (objectId, od['glatmean'], od['glonmean']))

File ~/miniconda3/lib/python3.10/site-packages/lasair/lasair.py:188, in lasair_client.sherlock_objects(self, objectIds, lite)
    178 """ Query the Sherlock database for context information about objects
    179     in the database.
    180 args:
   (...)
    185     list of dictionaries, one for each objectId.
    186 """
    187 input = {'objectIds':','.join(objectIds), 'lite':lite}
--> 188 result = self.fetch('sherlock/objects', input)
    189 return result

File ~/miniconda3/lib/python3.10/site-packages/lasair/lasair.py:81, in lasair_client.fetch(self, method, input)
     78     except:
     79         pass
---> 81 result = self.fetch_from_server(method, input)
     83 if 'error' in result:
     84     return result

File ~/miniconda3/lib/python3.10/site-packages/lasair/lasair.py:50, in lasair_client.fetch_from_server(self, method, input)
     48 elif r.status_code == 400:
     49     message = 'Bad Request:' + r.text
---> 50     raise LasairError(message)
     51 elif r.status_code == 401:
     52     message = 'Unauthorized'

LasairError: Bad Request:{"error":"{\"message\": \"Object Z not found\"}\n"}