Hi community, I wonder if how I can check if a par...
# ask-community
t
Hi community, I wonder if how I can check if a parameter is passed or not to an ops. For exemple, I have a Field(str, is_required=False) that I use only if it is explicitely set. How would you do that ? My idea is to set a default value to None and check if it is not None but don't find it pretty 🙂
1
z
if this is in the context of run config, you could just do something like
Copy code
if context.op_config.get("optional_param"):
    # use optional parameter
👍🏽 1
👍 1
t
Thanks for this idea. If I set a default_value it will return something here ? Just to see the counterpart
z
yes, setting a default_value for a Field will result in that value being present for that field if the user doesn't provide one. example:
Copy code
@op(config_schema={'optional': Field(str, is_required=False, default_value='something'})
def op_example(context):
    value = context.op_config['optional']
    # value should equal 'something' when user doesn't provide anything for the 'optional' field
👍 1
t
Thanks ! Very clear !
🎉 1