diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index f222eb706d15..5c912590e669 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -208,8 +208,18 @@ OPTIONAL_STR_TO_STR_DICT = Optional[Dict[str, str]] + +class TransformAction(TypedDict): + action: str + + +TRANSFORM_ACTIONS = Optional[List[TransformAction]] + mapper_registry = registry( - type_annotation_map={OPTIONAL_STR_TO_STR_DICT: JSONType}, + type_annotation_map={ + OPTIONAL_STR_TO_STR_DICT: JSONType, + TRANSFORM_ACTIONS: MutableJSONType, + }, ) # When constructing filters with in for a fixed set of ids, maximum @@ -4354,7 +4364,7 @@ class DatasetSource(Base, Dictifiable, Serializable): dataset_id: Mapped[Optional[int]] = mapped_column(ForeignKey("dataset.id"), index=True) source_uri: Mapped[Optional[str]] = mapped_column(TEXT) extra_files_path: Mapped[Optional[str]] = mapped_column(TEXT) - transform: Mapped[Optional[bytes]] = mapped_column(MutableJSONType) + transform: Mapped[TRANSFORM_ACTIONS] = mapped_column(MutableJSONType) dataset: Mapped[Optional["Dataset"]] = relationship(back_populates="sources") hashes: Mapped[List["DatasetSourceHash"]] = relationship(back_populates="source") dict_collection_visible_keys = ["id", "source_uri", "extra_files_path", "transform"] diff --git a/lib/galaxy/model/deferred.py b/lib/galaxy/model/deferred.py index d57622f700ba..33562bd1c39b 100644 --- a/lib/galaxy/model/deferred.py +++ b/lib/galaxy/model/deferred.py @@ -178,12 +178,12 @@ def ensure_materialized( def _stream_source(self, target_source: DatasetSource, datatype) -> str: path = stream_url_to_file(target_source.source_uri, file_sources=self._file_sources) - transform = target_source.transform or [] # type:ignore[var-annotated] + transform = target_source.transform or [] to_posix_lines = False spaces_to_tabs = False datatype_groom = False for transform_action in transform: - action = transform_action["action"] # type:ignore[index] + action = transform_action["action"] if action == "to_posix_lines": to_posix_lines = True elif action == "spaces_to_tabs": @@ -191,7 +191,7 @@ def _stream_source(self, target_source: DatasetSource, datatype) -> str: elif action == "datatype_groom": datatype_groom = True else: - raise Exception(f"Failed to materialize dataest, unknown transformation action {action} applied.") + raise Exception(f"Failed to materialize dataset, unknown transformation action {action} applied.") if to_posix_lines or spaces_to_tabs: convert_fxn = convert_function(to_posix_lines, spaces_to_tabs) convert_result = convert_fxn(path, False)