Commit c58e3f45 authored by davelopez's avatar davelopez
Browse files

Change datatype of deferred directly in request

Instead of spinning a celery task we just set the new datatype and skip the sniffing if `auto-detect` was requested.
parent 739b2e80
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -1621,9 +1621,17 @@ class HistoryItemOperator:
        if isinstance(item, HistoryDatasetAssociation):
            self.hda_manager.ensure_can_change_datatype(item)
            self.hda_manager.ensure_can_set_metadata(item)
            if not item.has_deferred_data:
            is_deferred = item.has_deferred_data
            item.dataset.state = item.dataset.states.SETTING_METADATA
            trans.sa_session.flush()
            if is_deferred:
                if params.datatype == "auto":  # if `auto` just keep the original guessed datatype
                    item.update()  # TODO: remove this `update` when we can properly track the operation results to notify the history
                else:
                    trans.app.datatypes_registry.change_datatype(item, params.datatype)
                item.dataset.state = item.dataset.states.DEFERRED
                trans.sa_session.flush()
            else:
                change_datatype.delay(dataset_id=item.id, datatype=params.datatype)

    def _change_dbkey(self, item: HistoryItemModel, params: ChangeDbkeyOperationParams):
+6 −5
Original line number Diff line number Diff line
@@ -1274,7 +1274,9 @@ class HistoryContentsApiBulkOperationTestCase(ApiTestCase):
            assert details["state"] == "deferred"
            assert details["extension"] == "bed"
            assert details["data_type"] == "galaxy.datatypes.interval.Bed"
            assert details["metadata_columns"]
            assert "metadata_columns" in details
            assert "metadata_delimiter" in details
            assert "metadata_comment_lines" in details

            new_datatype = "txt"
            payload = {
@@ -1287,16 +1289,15 @@ class HistoryContentsApiBulkOperationTestCase(ApiTestCase):
            bulk_operation_result = self._apply_bulk_operation(history_id, payload)
            self._assert_bulk_success(bulk_operation_result, expected_success_count=1)

            # Wait for celery tasks to finish
            time.sleep(2)  # I don't like this at all, is there another way to wait for celery here?

            history_contents = self._get_history_contents(history_id, query="?v=dev&view=detailed")
            for item in history_contents:
                assert item["state"] == "deferred"
                assert item["extension"] == "txt"
                assert item["data_type"] == "galaxy.datatypes.data.Text"
                # Should keep or discard old metadata?
                # It should discard old metadata
                assert "metadata_columns" not in item
                assert "metadata_delimiter" not in item
                assert "metadata_comment_lines" not in item

    @skip_without_tool("cat_data_and_sleep")
    def test_bulk_datatype_change_errors(self):