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

GAIA: The function upload_table in the TapPlus class must not allow table names that contain a dot #2971

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ Service fixes and enhancements
Infrastructure, Utility and Other Changes and Additions
-------------------------------------------------------

utils.tap
^^^^^^^^^


- ``TapPlus.upload_table`` should not allow table names to contain a
dot. ``ValueError`` is now raised for such cases. [#2971]


0.4.7 (2024-03-08)
Expand Down
2 changes: 2 additions & 0 deletions astroquery/utils/tap/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,8 @@ def upload_table(self, *, upload_resource=None, table_name=None,
raise ValueError("Missing mandatory argument 'upload_resource'")
if table_name is None:
raise ValueError("Missing mandatory argument 'table_name'")
if "." in table_name:
raise ValueError(f"Table name is not allowed to contain a dot: {table_name}")
if table_description is None:
description = ""
else:
Expand Down
15 changes: 15 additions & 0 deletions astroquery/utils/tap/tests/test_tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from astroquery.utils.tap.conn.tests.DummyResponse import DummyResponse
from astroquery.utils.tap.core import TapPlus
from astroquery.utils.tap import taputils
from astropy.table import Table


def read_file(filename):
Expand Down Expand Up @@ -936,3 +937,17 @@ def test_logout(mock_logout):
with pytest.raises(HTTPError):
tap.logout()
assert (mock_logout.call_count == 2)


def test_upload_table():
conn_handler = DummyConnHandler()
tap = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
a = [1, 2, 3]
b = ['a', 'b', 'c']
table = Table([a, b], names=['col1', 'col2'], meta={'meta': 'first table'})

table_name = 'hola.table_test_from_astropy'
with pytest.raises(ValueError) as exc_info:
tap.upload_table(upload_resource=table, table_name=table_name)

assert str(exc_info.value) == f"Table name is not allowed to contain a dot: {table_name}"
Loading