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

[23.0] Fix dataype_change not updating HDCA update_time #16099

Merged
merged 2 commits into from
May 17, 2023
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
9 changes: 9 additions & 0 deletions lib/galaxy/celery/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ def change_datatype(
set_metadata(hda_manager, ldda_manager, sa_session, dataset_id, model_class)


@galaxy_task(action="touch update_time of object")
def touch(sa_session: galaxy_scoped_session, item_id: int, model_class: str = "HistoryDatasetCollectionAssociation"):
if model_class != "HistoryDatasetCollectionAssociation":
raise NotImplementedError(f"touch method not implemented for '{model_class}'")
item = sa_session.query(model.HistoryDatasetCollectionAssociation).filter_by(id=item_id).one()
item.touch()
sa_session.flush()


@galaxy_task(action="set dataset association metadata")
def set_metadata(
hda_manager: HDAManager,
Expand Down
9 changes: 9 additions & 0 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
registry,
relationship,
)
from sqlalchemy.orm.attributes import flag_modified
from sqlalchemy.orm.collections import attribute_mapped_collection
from sqlalchemy.sql import exists
from typing_extensions import Protocol
Expand Down Expand Up @@ -6212,6 +6213,14 @@ def dataset_dbkeys_and_extensions_summary(self):
def job_source_id(self):
return self.implicit_collection_jobs_id or self.job_id

def touch(self):
# cause an update to be emitted, so that e.g. update_time is incremented and triggers are notified
if getattr(self, "name", None):
# attribute to flag doesn't really matter as long as it's not null (and primary key also doesn't work)
flag_modified(self, "name")
if self.collection:
flag_modified(self.collection, "collection_type")

def to_hda_representative(self, multiple=False):
rval = []
for dataset in self.collection.dataset_elements:
Expand Down
6 changes: 4 additions & 2 deletions lib/galaxy/webapps/galaxy/services/history_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Union,
)

from celery import group
from celery import chain
from pydantic import (
Extra,
Field,
Expand All @@ -28,6 +28,7 @@
materialize as materialize_task,
prepare_dataset_collection_download,
prepare_history_content_download,
touch,
write_history_content_to,
)
from galaxy.managers import (
Expand Down Expand Up @@ -1429,7 +1430,8 @@ def _change_datatype(
if wrapped_task:
wrapped_tasks.append(wrapped_task)
trans.sa_session.flush()
group(wrapped_tasks).delay()
# chain these for sequential execution. chord would be nice, but requires a non-RPC backend.
chain(*wrapped_tasks, touch.si(item_id=item.id, model_class="HistoryDatasetCollectionAssociation")).delay()

def _change_item_datatype(
self, item: HistoryDatasetAssociation, params: ChangeDatatypeOperationParams, trans: ProvidesHistoryContext
Expand Down
10 changes: 8 additions & 2 deletions lib/galaxy_test/api/test_history_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,13 +1081,14 @@ def test_bulk_datatype_change_collection(self):
_, collection_ids, history_contents = self._create_test_history_contents(history_id)

history_contents = self._get_history_contents(history_id, query="?v=dev&keys=extension,data_type,metadata")
original_collection_update_times = []
for item in history_contents:
if item["history_content_type"] == "dataset":
assert item["extension"] == "txt"
assert item["data_type"] == "galaxy.datatypes.data.Text"
assert "metadata_column_names" not in item

self.dataset_populator.wait_for_history_jobs(history_id)
if item["history_content_type"] == "dataset_collection":
original_collection_update_times.append(item["update_time"])

expected_datatype = "tabular"
# Change datatype of all datasets
Expand All @@ -1107,11 +1108,16 @@ def test_bulk_datatype_change_collection(self):
self.dataset_populator.wait_for_history(history_id)

history_contents = self._get_history_contents(history_id, query="?v=dev&keys=extension,data_type,metadata")
new_collection_update_times = []
for item in history_contents:
if item["history_content_type"] == "dataset":
assert item["extension"] == "tabular"
assert item["data_type"] == "galaxy.datatypes.tabular.Tabular"
assert "metadata_column_names" in item
if item["history_content_type"] == "dataset_collection":
new_collection_update_times.append(item["update_time"])

assert original_collection_update_times != new_collection_update_times

def test_bulk_datatype_change_should_skip_set_metadata_on_deferred_data(self):
with self.dataset_populator.test_history() as history_id:
Expand Down