diff --git a/lib/galaxy/managers/tool_source.py b/lib/galaxy/managers/tool_source.py index 6e9aec1f641..a2872f5dcca 100644 --- a/lib/galaxy/managers/tool_source.py +++ b/lib/galaxy/managers/tool_source.py @@ -67,11 +67,19 @@ def get_or_create_tool_source(session: Session, tool) -> ToolSource: def tool_source_identity_hash(tool: Any) -> str: dynamic_tool = getattr(tool, "dynamic_tool", None) - identity: tuple[str, ...] if dynamic_tool is not None and dynamic_tool.id is not None: identity = ("dynamic", str(dynamic_tool.id)) - else: - identity = ("static", tool.id or "", tool.version or "") + return hashlib.sha256("\0".join(identity).encode("utf-8")).hexdigest() + return static_tool_source_identity_hash(tool.id, tool.version) + + +def static_tool_source_identity_hash(tool_id: str | None, tool_version: str | None) -> str: + """Identity hash for a persisted source with no dynamic-tool linkage. + + Shared with ``galaxy.tool_source_store`` writers, which persist + config-file tool sources and therefore always carry a static identity. + """ + identity = ("static", tool_id or "", tool_version or "") return hashlib.sha256("\0".join(identity).encode("utf-8")).hexdigest() diff --git a/lib/galaxy/tool_source_store/database.py b/lib/galaxy/tool_source_store/database.py index a2402f68bba..9f441eb21b0 100644 --- a/lib/galaxy/tool_source_store/database.py +++ b/lib/galaxy/tool_source_store/database.py @@ -22,6 +22,7 @@ from sqlalchemy import ( ) from sqlalchemy.orm import Session +from galaxy.managers.tool_source import static_tool_source_identity_hash from galaxy.model import ( ToolIndexCache, ToolSource as ToolSourceModel, @@ -112,6 +113,11 @@ class DatabaseToolSourceStore(ToolSourceStore): hash=tool_source.hash, source=source_data, source_class=tool_source.tool_source_class, + tool_id=tool_source.tool_id, + tool_version=tool_source.tool_version, + # Same "static" identity as galaxy.managers.tool_source.tool_source_identity_hash — + # store-backed sources never carry a dynamic tool. + identity_hash=static_tool_source_identity_hash(tool_source.tool_id, tool_source.tool_version), ) session.add(model) session.flush()