Skip to content

Commit c0a1a84

Browse files
authored
Merge pull request #3439 from esdc-esac-esa-int/ESA_euclid_EUCLIDSWRQ-258_GAIASWRQ-125_include_schema_in_delete_user_table_method
2 parents 1e3eb77 + ef77031 commit c0a1a84

File tree

5 files changed

+87
-7
lines changed

5 files changed

+87
-7
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ esa.hubble
2424
Infrastructure, Utility and Other Changes and Additions
2525
-------------------------------------------------------
2626

27+
utils.tap
28+
^^^^^^^^^
29+
30+
- ``TapPlus.delete_user_table`` includes the schema name to be compatible with TAP+ version >= 10.x. [#3439]
31+
2732

2833

2934
0.4.11 (2025-09-19)

astroquery/gaia/core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import os
1414
import shutil
1515
import zipfile
16+
from collections.abc import Iterable
17+
1618
from astropy import units
1719
from astropy import units as u
1820
from astropy.coordinates import Angle
@@ -21,7 +23,6 @@
2123
from astropy.table import Table
2224
from astropy.units import Quantity
2325
from astropy.utils.decorators import deprecated_renamed_argument
24-
from collections.abc import Iterable
2526
from requests import HTTPError
2627

2728
from astroquery import log
@@ -869,13 +870,13 @@ def cross_match_basic(self, *, table_a_full_qualified_name, table_a_column_ra, t
869870
Parameters
870871
----------
871872
table_a_full_qualified_name : str, mandatory
872-
a full qualified table name (i.e. schema name and table name)
873+
a full qualified table name (i.e. schema name and table name, "user_<user_name>.<table_name>" )
873874
table_a_column_ra : str, mandatory
874875
the ‘ra’ column in the table table_a_full_qualified_name
875876
table_a_column_dec : str, mandatory
876877
the ‘dec’ column in the table table_a_full_qualified_name
877878
table_b_full_qualified_name : str, optional, default MAIN_GAIA_TABLE
878-
a full qualified table name (i.e. schema name and table name)
879+
a full qualified table name (i.e. schema name and table name, "user_<user_name>.<table_name>" )
879880
table_b_column_ra : str, optional, default MAIN_GAIA_TABLE_RA
880881
the ‘ra’ column in the table table_b_full_qualified_name
881882
table_b_column_dec : str, default MAIN_GAIA_TABLE_DEC

astroquery/utils/tap/conn/tests/DummyConnHandler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
class DummyConnHandler:
2424

2525
def __init__(self):
26+
self.cookie = None
2627
self.request = None
2728
self.data = None
2829
self.fileExt = ".ext"
@@ -168,3 +169,6 @@ def execute_upload(self, data,
168169
content_type="application/x-www-form-urlencoded", *,
169170
verbose=False):
170171
return self.defaultResponse
172+
173+
def set_cookie(self, cookie):
174+
self.cookie = cookie

astroquery/utils/tap/core.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,16 +1527,27 @@ def delete_user_table(self, *, table_name=None, force_removal=False, verbose=Fal
15271527
verbose : bool, optional, default 'False'
15281528
flag to display information about the process
15291529
"""
1530+
15301531
if table_name is None:
15311532
raise ValueError("Table name cannot be null")
1533+
1534+
if '.' not in table_name:
1535+
if self.__user is None:
1536+
raise ValueError("You must login to delete the table")
1537+
full_qualified_table = 'user_' + self.__user + '.' + table_name
1538+
else:
1539+
if not table_name.startswith("user_"):
1540+
raise ValueError(f"Invalid table name {table_name}: expected format user_<user_name>.<table_name>")
1541+
full_qualified_table = table_name
1542+
15321543
if force_removal is True:
15331544
args = {
1534-
"TABLE_NAME": str(table_name),
1545+
"TABLE_NAME": str(full_qualified_table),
15351546
"DELETE": "TRUE",
15361547
"FORCE_REMOVAL": "TRUE"}
15371548
else:
15381549
args = {
1539-
"TABLE_NAME": str(table_name),
1550+
"TABLE_NAME": str(full_qualified_table),
15401551
"DELETE": "TRUE",
15411552
"FORCE_REMOVAL": "FALSE"}
15421553
connHandler = self.__getconnhandler()
@@ -1545,7 +1556,7 @@ def delete_user_table(self, *, table_name=None, force_removal=False, verbose=Fal
15451556
print(response.status, response.reason)
15461557
print(response.getheaders())
15471558
connHandler.check_launch_response_status(response, verbose, 200)
1548-
msg = f"Table '{table_name}' deleted."
1559+
msg = f"Table '{full_qualified_table}' deleted."
15491560
log.info(msg)
15501561

15511562
def rename_table(self, *, table_name=None, new_table_name=None, new_column_names_dict=None, verbose=False):
@@ -1647,7 +1658,7 @@ def update_user_table(self, *, table_name=None, list_of_changes=(), verbose=Fals
16471658
for value in change:
16481659
if value is None:
16491660
raise ValueError("None of the values for the changes can be null")
1650-
if (index == 1 and value != 'utype' and value != 'ucd' and value != 'flags' and value != 'indexed'):
1661+
if index == 1 and value != 'utype' and value != 'ucd' and value != 'flags' and value != 'indexed':
16511662
raise ValueError("Position 2 of all changes must be 'utype', 'ucd', 'flags' or 'indexed'")
16521663
index = index + 1
16531664

astroquery/utils/tap/tests/test_tap.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,65 @@ def test_rename_table():
882882
tap.rename_table(table_name=tableName, new_table_name=newTableName, new_column_names_dict=newColumnNames)
883883

884884

885+
def test_delete_user_table():
886+
tableName = 'user_test.table_test_rename'
887+
conn_handler = DummyConnHandler()
888+
dummyResponse = DummyResponse(200)
889+
890+
url_encode = urlencode({'DELETE': 'TRUE', 'FORCE_REMOVAL': 'FALSE', 'TABLE_NAME': 'user_test.table_test_rename'})
891+
conn_handler.set_default_response(dummyResponse)
892+
conn_handler.execute_upload(data=url_encode)
893+
tap = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
894+
tap.delete_user_table(table_name=tableName, force_removal=False, verbose=False)
895+
896+
897+
def test_delete_user_table_2():
898+
conn_handler = DummyConnHandler()
899+
dummyResponse = DummyResponse(200)
900+
901+
headers = [('Date', 'Sat, 12 Apr 2025 05:10:47 GMT'),
902+
('Server', 'Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips mod_jk/1.2.43'),
903+
('Set-Cookie', 'JSESSIONID=E677B51BA5C4837347D1E17D4E36647E; Path=/data-server; Secure; HttpOnly'),
904+
('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'),
905+
('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'), ('Pragma', 'no-cache'),
906+
('Expires', '0'), ('X-Frame-Options', 'SAMEORIGIN'),
907+
('Set-Cookie', 'SESSION=ZjQ3MjIzMDAtNjNiYy00Mj; Path=/data-server; Secure; HttpOnly; SameSite=Lax'),
908+
('Transfer-Encoding', 'chunked'), ('Content-Type', 'text/plain; charset=UTF-8')]
909+
910+
dummyResponse.set_data(method='POST', headers=headers)
911+
912+
url_encode = urlencode({'DELETE': 'TRUE', 'FORCE_REMOVAL': 'FALSE', 'TABLE_NAME': 'user_test.table_test_rename'})
913+
conn_handler.set_default_response(dummyResponse)
914+
conn_handler.execute_upload(data=url_encode)
915+
tap = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
916+
tap.login(user="user", password="password")
917+
918+
tableName = 'table_test_rename'
919+
920+
tap.delete_user_table(table_name=tableName, force_removal=False, verbose=False)
921+
922+
923+
def test_delete_user_table_exception():
924+
tableName = 'test.table_test_rename'
925+
conn_handler = DummyConnHandler()
926+
dummyResponse = DummyResponse(200)
927+
928+
url_encode = urlencode({'DELETE': 'TRUE', 'FORCE_REMOVAL': 'FALSE', 'TABLE_NAME': 'user_test.table_test_rename'})
929+
conn_handler.set_default_response(dummyResponse)
930+
conn_handler.execute_upload(data=url_encode)
931+
tap = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
932+
933+
with pytest.raises(ValueError,
934+
match="Invalid table name test.table_test_rename: expected format user_<user_name>.<table_name"):
935+
tap.delete_user_table(table_name=tableName, force_removal=False, verbose=False)
936+
937+
#
938+
939+
tableName = 'table_test_rename'
940+
with pytest.raises(ValueError, match="You must login to delete the table"):
941+
tap.delete_user_table(table_name=tableName, force_removal=False, verbose=False)
942+
943+
885944
def __find_table(schemaName, tableName, tables):
886945
qualified_name = f"{schemaName}.{tableName}"
887946
for table in tables:

0 commit comments

Comments
 (0)