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

getdatalink() exits messily when there isn't a datalink #328

Open
trjaffe opened this issue May 11, 2022 · 2 comments · May be fixed by #607
Open

getdatalink() exits messily when there isn't a datalink #328

trjaffe opened this issue May 11, 2022 · 2 comments · May be fixed by #607
Labels

Comments

@trjaffe
Copy link
Contributor

trjaffe commented May 11, 2022

Most simply,

import pyvo as vo
import astropy.coordinates as coord
coords = coord.SkyCoord.from_name("m51")
skyview=vo.regsearch(servicetype='sia',keywords=['skyview digitized sky survey'])[0]
results=skyview.search(pos=coords,radius=0.1)
results[0].getdatalink()

This results in an expected exception because skyview doesn't offer datalinks with its results:

DALServiceError: No Adhoc Service with ivo-id ivo://ivoa.net/std/datalink!

but then there's another exception because getdatalink() is doing something I don't understand. Here's the code in adhoc.py around line 243:

    def getdatalink(self):
        try:
            datalink = self._results.get_adhocservice_by_ivoid(DATALINK_IVOID)

            query = DatalinkQuery.from_resource(self, datalink, session=self._session)
            return query.execute()
        except DALServiceError:
            return DatalinkResults.from_result_url(self.getdataurl(), session=self._session)

The problem is that the service is returning a URL to a FITS file. When the get_adhocservice_by_ivoid() fails to find a datalink in the metadata of the result, it excepts into the call to DatalinkResults.from_result_url(). The problem in this case is that the data URL of this result is to a FITS file, and it's expecting a VOTable result, and it barfs trying to parse the FITS file as a VOTable.

At first I thought that there should be a check for the current content_type, e.g., only call that when it's XML or VOTable or something. But I don't understand what the use case is for this anyway, so I'm not sure what fix to propose.

Personally, I think that if there is no datalink, the call to getdatalink() should return None rather than an exception.

@msdemlei
Copy link
Contributor

msdemlei commented May 12, 2022 via email

@trjaffe
Copy link
Contributor Author

trjaffe commented May 12, 2022

Oh, I see, this is also how to get nested datalinks, which aren't defined as resources either. I should have realized that. So indeed, all it needs is a small fix to check the type.

@bsipocz bsipocz added the bug label Jan 24, 2023
@d-giles d-giles linked a pull request Oct 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants