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

Make TAP job deletion optional defaulting to True #640

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Enhancements and Fixes
----------------------

- Make deletion of TAP jobs optional via a delete flag. Default: True
bsipocz marked this conversation as resolved.
Show resolved Hide resolved

Deprecations and Removals
-------------------------
Expand Down
28 changes: 20 additions & 8 deletions pyvo/dal/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@

def run_async(
self, query, *, language="ADQL", maxrec=None, uploads=None,
**keywords):
delete=True, **keywords):
"""
runs async query and returns its result

Expand All @@ -297,6 +297,8 @@
the maximum records to return. defaults to the service default
uploads : dict
a mapping from table names to objects containing a votable
delete : bool
delete the job after fetching the results

Returns
-------
Expand All @@ -323,7 +325,9 @@
job = job.run().wait()
job.raise_if_error()
result = job.fetch_result()
job.delete()

if delete:
job.delete()

return result

Expand Down Expand Up @@ -643,17 +647,22 @@
job = cls(response.url, session=session)
return job

def __init__(self, url, *, session=None):
def __init__(self, url, *, session=None, delete=True):
"""
initialize the job object with the given url and fetch remote values

Parameters
----------
url : str
the job url
session : object, optional
session to use for network requests
delete : bool, optional
whether to delete the job when exiting (default: True)
"""
self._url = url
self._session = use_session(session)
self._delete_on_exit = delete
self._update()

def __enter__(self):
Expand All @@ -664,12 +673,15 @@

def __exit__(self, exc_type, exc_val, exc_tb):
"""
Exits the context. The job is silently deleted.
Exits the context. Unless delete=False was set at initialization,
the job is deleted. Any deletion errors are silently ignored
to ensure proper context exit.
"""
try:
self.delete()
except Exception:
pass
if self._delete_on_exit:
try:
self.delete()
except DALServiceError:
pass

Check warning on line 684 in pyvo/dal/tap.py

View check run for this annotation

Codecov / codecov/patch

pyvo/dal/tap.py#L680-L684

Added lines #L680 - L684 were not covered by tests

def _update(self, wait_for_statechange=False, timeout=10.):
"""
Expand Down
Loading