Skip to content

Validate matched multi-input expansion errors before async job prep#23058

Draft
SID-6921 wants to merge 3 commits into
galaxyproject:devfrom
SID-6921:fix-tool-input-matched-validation-22884
Draft

Validate matched multi-input expansion errors before async job prep#23058
SID-6921 wants to merge 3 commits into
galaxyproject:devfrom
SID-6921:fix-tool-input-matched-validation-22884

Conversation

@SID-6921

@SID-6921 SID-6921 commented Jul 3, 2026

Copy link
Copy Markdown

Summary

  • catch InputMatchedException in tool input expansion paths (expand_incoming and expand_incoming_async)
  • convert these to RequestParameterInvalidException so malformed matched-input requests are surfaced as request validation errors instead of bubbling into async prep paths

Problem

Issue #22884 reports malformed matched inputs reaching async prep and generating noisy internal errors around Celery job preparation. This patch validates the error at API/tool expansion boundary and returns a clear request-level error.

Notes

Testing

  • python -m py_compile lib/galaxy/tools/init.py
  • Full unit tests are not runnable in this Windows environment because Galaxy's test stack imports POSIX-only pwd in conftest.

Signed-off-by: SID <nandasiddhardha@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR improves request validation behavior by translating InputMatchedException failures from meta-parameter expansion into a user-facing RequestParameterInvalidException.

Changes:

  • Import InputMatchedException for handling expansion failures.
  • Wrap expand_meta_parameters_async(...) in try/except to raise RequestParameterInvalidException.
  • Wrap expand_meta_parameters(...) in try/except to raise RequestParameterInvalidException.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/galaxy/tools/__init__.py Outdated
Comment on lines +2139 to +2144
try:
expanded_incomings, job_tool_states, collection_info = expand_meta_parameters_async(
request_context.app, self, tool_request_internal_state
)
except InputMatchedException as exc:
raise exceptions.RequestParameterInvalidException(str(exc)) from exc
@mvdbeek

mvdbeek commented Jul 3, 2026

Copy link
Copy Markdown
Member

This looks good but could you include a test for the API level behavior ?

with self.dataset_populator.test_history() as history_id:
response = self.dataset_populator.tool_request_raw(
tool_id="data_manager",
inputs={"ignored_value": "test", "exit_code": 0},
history_id=history_id,
strict=False,
)
response.raise_for_status()
tool_request_id = response.json()["tool_request_id"]
submitted = self.dataset_populator.wait_on_tool_request(tool_request_id)
assert submitted, self.dataset_populator.get_tool_request(tool_request_id)

is more or less how this could look like

… jobs

Signed-off-by: SID <nandasiddhardha@gmail.com>
@SID-6921

SID-6921 commented Jul 3, 2026

Copy link
Copy Markdown
Author

Added the requested API-level regression test in 0995097. New test: test_async_job_submission_rejects_mismatched_multi_inputs in lib/galaxy_test/api/test_jobs.py. It verifies async POST /api/jobs returns 400 with a validation error when matched multi-input lengths differ.

@mvdbeek

mvdbeek commented Jul 5, 2026

Copy link
Copy Markdown
Member

@mvdbeek
mvdbeek marked this pull request as draft July 7, 2026 14:21
Consolidates duplicate InputMatchedException->RequestParameterInvalidException
translation logic between expand_incoming_async and expand_incoming methods.

This improves maintainability and ensures consistent error handling across
both API paths for job submission (sync and async). The helper method
_raise_matched_input_errors clearly documents the intent: mismatched
multi-input parameter lengths should surface as 400 validation errors.

Fixes: duplicated exception handling patterns
Part of: PR galaxyproject#23058 - Validate matched multi-input expansion errors
@SID-6921

Copy link
Copy Markdown
Author

I've refactored the code to extract the duplicate InputMatchedException handling into a helper method _raise_matched_input_errors. This consolidates the logic between \�xpand_incoming_async\ and \�xpand_incoming, improving maintainability and ensuring consistent error handling.

Changes made:

  • Added helper method to convert InputMatchedException to RequestParameterInvalidException
  • Updated both API paths (sync and async) to use the helper
  • This ensures mismatched multi-input parameter lengths surface as 400 validation errors

The refactored code maintains the same behavior while reducing duplication. Tests are running now.

@mvdbeek

mvdbeek commented Jul 15, 2026

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

3 participants