astroquery icon indicating copy to clipboard operation
astroquery copied to clipboard

Gaia (and Tap/TapPlus?) .search_async_jobs() broken

Open adrn opened this issue 3 years ago • 6 comments

I was trying to use the Gaia.load_async_job() method to retrieve a job by name, but I get an AttributeError caused by this line because Filter (jobfilter) does not have a createUrlRequest() method (it instead has .create_url_data_request()). I tried fixing the method name in a local clone, but then I still get an error:

full traceback here
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-117-439c23e3fa7d> in <module>
----> 1 Gaia.load_async_job(name='pw1_dr3_region')

~/projects/astropy-all/astroquery/astroquery/utils/tap/core.py in load_async_job(self, jobid, name, verbose, load_results)
    483             jobfilter = Filter()
    484             jobfilter.add_filter('name', name)
--> 485             jobs = self.search_async_jobs(jobfilter)
    486             if jobs is None or len(jobs) < 1:
    487                 log.info(f"No job found for name '{name}'")

~/projects/astropy-all/astroquery/astroquery/utils/tap/core.py in search_async_jobs(self, jobfilter, verbose)
   1298             data = jobfilter.create_url_data_request()
   1299             if data is not None:
-> 1300                 subContext = f"{subContext}?{self.__appendData(data)}"
   1301         connHandler = self.__getconnhandler()
   1302         response = connHandler.execute_tapget(subContext, verbose=verbose)
AttributeError: 'GaiaClass' object has no attribute '_TapPlus__appendData'
AttributeError: 'GaiaClass' object has no attribute '_TapPlus__appendData'

I'm confused because the line of code is calling self.__appendData() but the attribute error is for _TapPlus__appendData -- any ideas?

Thanks!

adrn avatar Jul 05 '22 19:07 adrn

The attribute name getting modified like that is the result of name mangling. The __appendData() method is defined in the Tap class, so it can be accessed as _Tap__appendData().

eerovaher avatar Jul 05 '22 22:07 eerovaher

Ah, thanks -- I've never used this before. In this case, GaiaClass subclasses TapPlus, which subclasses Tap where the method lives. It doesn't seem to like that the method lives in a grandparent class -- do we need to implement a custom search_async_jobs() on GaiaClass?

adrn avatar Jul 05 '22 23:07 adrn

It is not obvious to me that overwriting search_async_jobs() would be the best solution. I would say the problem is that __appendData() is defined in Tap, but only used in TapPlus, which is especially confusing because of the name mangling. Does moving __appendData() from Tap to TapPlus help fixing GaiaClass.load_async_job()?

eerovaher avatar Jul 06 '22 01:07 eerovaher

That might also be a path forward but I'm not really familiar with the source code in astroquery.utils.tap or where it's used (in jwst and gaia, at least)!

adrn avatar Jul 06 '22 01:07 adrn

git grep appendData finds two matches in all of astroquery. One of them is the method definition in Tap, the other is included in your traceback. Moving the method to TapPlus should therefore not break anything.

eerovaher avatar Jul 06 '22 01:07 eerovaher

A possible solution to the issue described by @adrn has been implemented in the PR https://github.com/astropy/astroquery/pull/2967

cosmoJFH avatar Apr 20 '24 15:04 cosmoJFH