|
4 | 4 | ) |
5 | 5 | from uuid import uuid4 |
6 | 6 |
|
7 | | -from pydantic import UUID4 |
| 7 | +from pydantic import ( |
| 8 | + UUID4, |
| 9 | + ValidationError, |
| 10 | +) |
8 | 11 | from sqlalchemy import select |
9 | 12 |
|
10 | 13 | from galaxy.exceptions import ( |
|
30 | 33 | ) |
31 | 34 | from galaxy.security.idencoding import IdEncodingHelper |
32 | 35 | from galaxy.structured_app import StructuredApp |
| 36 | +from galaxy.tool_util_models.parameters import DataOrCollectionRequestAdapter |
33 | 37 | from galaxy.util import safe_str_cmp |
34 | 38 | from .context import ProvidesUserContext |
35 | 39 |
|
@@ -73,11 +77,25 @@ def create_workflow_landing_request(self, payload: CreateWorkflowLandingRequestP |
73 | 77 | model.workflow_source = payload.workflow_id |
74 | 78 | model.uuid = uuid4() |
75 | 79 | model.client_secret = payload.client_secret |
76 | | - model.request_state = payload.request_state |
| 80 | + model.request_state = self.validate_workflow_request_state(payload.request_state) |
77 | 81 | model.public = payload.public |
78 | 82 | self._save(model) |
79 | 83 | return self._workflow_response(model) |
80 | 84 |
|
| 85 | + def validate_workflow_request_state(self, request_state: Optional[dict]) -> Optional[dict]: |
| 86 | + # This would ideally be run in the context of a workflow input definition |
| 87 | + if isinstance(request_state, dict): |
| 88 | + for key, value in request_state.items(): |
| 89 | + if isinstance(value, dict): |
| 90 | + try: |
| 91 | + # persist values after model validators and aliases have been applied |
| 92 | + request_state[key] = DataOrCollectionRequestAdapter.validate_python(value).model_dump( |
| 93 | + by_alias=True, exclude_unset=True, mode="json" |
| 94 | + ) |
| 95 | + except ValidationError: |
| 96 | + pass |
| 97 | + return request_state |
| 98 | + |
81 | 99 | def claim_tool_landing_request( |
82 | 100 | self, trans: ProvidesUserContext, uuid: UUID4, claim: Optional[ClaimLandingPayload] |
83 | 101 | ) -> ToolLandingRequest: |
|
0 commit comments