astropy / astroquery

Functions and classes to access online data resources. Maintainers: @keflavich and @bsipocz and @ceb8
http://astroquery.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
688 stars 392 forks source link

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

Open adrn opened 2 years ago

adrn commented 2 years ago

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 ```python --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in ----> 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!

eerovaher commented 2 years ago

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().

adrn commented 2 years ago

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?

eerovaher commented 2 years ago

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()?

adrn commented 2 years ago

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)!

eerovaher commented 2 years ago

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.

cosmoJFH commented 2 months ago

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