Skip to content

Commit

Permalink
Use request context for parameter helper
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Jan 26, 2016
1 parent 0521644 commit 8bd4cab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions lib/galaxy/tools/__init__.py
Expand Up @@ -1629,14 +1629,15 @@ def params_to_strings( self, params, app ):
def params_from_strings( self, params, app, ignore_errors=False ):
return params_from_strings( self.inputs, params, app, ignore_errors )

def check_and_update_param_values( self, values, trans, update_values=True ):
def check_and_update_param_values( self, values, trans, update_values=True, workflow_building_mode=False ):
"""
Check that all parameters have values, and fill in with default
values where necessary. This could be called after loading values
from a database in case new parameters have been added.
"""
messages = {}
self.check_and_update_param_values_helper( self.inputs, values, trans, messages, update_values=update_values )
request_context = WorkRequestContext( app=trans.app, user=trans.user, history=trans.history, workflow_building_mode=workflow_building_mode )
self.check_and_update_param_values_helper( self.inputs, values, request_context, messages, update_values=update_values )
return messages

def check_and_update_param_values_helper( self, inputs, values, trans, messages, context=None, prefix="", update_values=True ):
Expand All @@ -1654,18 +1655,18 @@ def check_and_update_param_values_helper( self, inputs, values, trans, messages,
messages[ input.name ] = cond_messages
test_value = input.test_param.get_initial_value( trans, context )
current_case = input.get_current_case( test_value, trans )
self.check_and_update_param_values_helper( input.cases[ current_case ].inputs, {}, trans, cond_messages, context, prefix )
self.check_and_update_param_values_helper( input.cases[ current_case ].inputs, {}, trans, cond_messages, context, prefix, update_values=update_values )
elif isinstance( input, Repeat ):
if input.min:
messages[ input.name ] = []
for i in range( input.min ):
rep_prefix = prefix + "%s %d > " % ( input.title, i + 1 )
rep_dict = dict()
messages[ input.name ].append( rep_dict )
self.check_and_update_param_values_helper( input.inputs, {}, trans, rep_dict, context, rep_prefix )
self.check_and_update_param_values_helper( input.inputs, {}, trans, rep_dict, context, rep_prefix, update_values=update_values )
elif isinstance( input, Section ):
messages[ input.name ] = {}
self.check_and_update_param_values_helper( input.inputs, {}, trans, messages[ input.name ], context, prefix )
self.check_and_update_param_values_helper( input.inputs, {}, trans, messages[ input.name ], context, prefix, update_values=update_values )
else:
messages[ input.name ] = "No value found for '%s%s', using default" % ( prefix, input.label )
values[ input.name ] = input.get_initial_value( trans, context )
Expand All @@ -1674,7 +1675,7 @@ def check_and_update_param_values_helper( self, inputs, values, trans, messages,
if isinstance( input, Repeat ):
for i, d in enumerate( values[ input.name ] ):
rep_prefix = prefix + "%s %d > " % ( input.title, i + 1 )
self.check_and_update_param_values_helper( input.inputs, d, trans, messages, context, rep_prefix )
self.check_and_update_param_values_helper( input.inputs, d, trans, messages, context, rep_prefix, update_values=update_values )
elif isinstance( input, Conditional ):
group_values = values[ input.name ]
use_initial_value = False
Expand All @@ -1692,10 +1693,10 @@ def check_and_update_param_values_helper( self, inputs, values, trans, messages,
messages[ child_input.name ] = "Value no longer valid for '%s%s', replacing with default" % ( prefix, child_input.label )
else:
current = group_values["__current_case__"]
self.check_and_update_param_values_helper( input.cases[current].inputs, group_values, trans, messages, context, prefix )
self.check_and_update_param_values_helper( input.cases[current].inputs, group_values, trans, messages, context, prefix, update_values=update_values )
elif isinstance( input, Section ):
messages[ input.name ] = {}
self.check_and_update_param_values_helper( input.inputs, values[ input.name ], trans, messages[ input.name ], context, prefix )
self.check_and_update_param_values_helper( input.inputs, values[ input.name ], trans, messages[ input.name ], context, prefix, update_values=update_values )
else:
# Regular tool parameter, no recursion needed
try:
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/tools/evaluation.py
Expand Up @@ -54,7 +54,7 @@ def set_compute_environment( self, compute_environment, get_special=None ):
incoming = self.tool.params_from_strings( incoming, self.app )

# Full parameter validation
request_context = WorkRequestContext( app=self.app, user=job.history.user, history=job.history )
request_context = WorkRequestContext( app=self.app, user=job.history and job.history.user, history=job.history )

def validate_inputs( input, value, prefixed_name, prefixed_label, context ):
value = input.from_html( value, request_context, context )
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/workflow/modules.py
Expand Up @@ -1080,7 +1080,7 @@ def item_callback( trans, key, input, value, error, old_value, context ):

def check_and_update_state( self ):
inputs = self.state.inputs
return self.tool.check_and_update_param_values( inputs, self.trans )
return self.tool.check_and_update_param_values( inputs, self.trans, workflow_building_mode=True )

def compute_runtime_state( self, trans, step_updates=None, source="html" ):
# Warning: This method destructively modifies existing step state.
Expand Down

0 comments on commit 8bd4cab

Please sign in to comment.