Skip to content

Commit

Permalink
Merge pull request #2971 from esdc-esac-esa-int/ESA_gaia_avoid_upload…
Browse files Browse the repository at this point in the history
…_tables_with_dots

GAIA: The function upload_table in the TapPlus class must not allow table names that contain a dot
  • Loading branch information
bsipocz committed Mar 18, 2024
2 parents b530378 + 3404e94 commit 722385a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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}"

0 comments on commit 722385a

Please sign in to comment.