Skip to content

Commit 7893620

Browse files
committed
Guard run_user_tool against legacy half-deactivated UDT rows
Before the manager fix in the prior commit, deactivate_unprivileged_tool only flipped UserDynamicToolAssociation.active, leaving DynamicTool.active true. Any deployment that deactivated UDTs through the existing /api/unprivileged_tools DELETE endpoint before this branch landed has rows in that half-state. Checking dynamic_tool.active alone would let those legacy entries run via run_user_tool. Also verify the user's association is active so legacy rows surface as "deactivated" instead.
1 parent e94750c commit 7893620

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

lib/galaxy/agents/operations.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,14 +920,28 @@ def delete_user_tool(self, uuid: str) -> dict[str, Any]:
920920
return {"uuid": uuid, "deactivated": True}
921921

922922
def run_user_tool(self, history_id: str, tool_uuid: str, inputs: dict[str, Any]) -> dict[str, Any]:
923+
from sqlalchemy import select
924+
925+
from galaxy.model import UserDynamicToolAssociation
926+
923927
user = self.trans.user
924928
if not user:
925929
raise ValueError("User must be authenticated")
926930

927931
dynamic_tool = self.dynamic_tools_manager.get_unprivileged_tool_by_uuid(user, tool_uuid)
928932
if dynamic_tool is None:
929933
raise ValueError(f"User-defined tool {tool_uuid!r} not found")
930-
if not dynamic_tool.active:
934+
# Check both DynamicTool.active and the user-association.active. Pre-fix
935+
# rows may have only the association deactivated; checking just
936+
# dynamic_tool.active would miss those legacy deletions.
937+
session = self.dynamic_tools_manager.session()
938+
assoc_active = session.scalar(
939+
select(UserDynamicToolAssociation.active).where(
940+
UserDynamicToolAssociation.user_id == user.id,
941+
UserDynamicToolAssociation.dynamic_tool_id == dynamic_tool.id,
942+
)
943+
)
944+
if not dynamic_tool.active or not assoc_active:
931945
raise ValueError(f"User-defined tool {tool_uuid!r} is deactivated")
932946

933947
payload = {

0 commit comments

Comments
 (0)