https://dagster.io/ logo
#ask-community
Title
# ask-community
t

Thomas

05/10/2022, 11:22 AM
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

Zach

05/10/2022, 3:15 PM
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

Thomas

05/10/2022, 3:27 PM
Thanks for this idea. If I set a default_value it will return something here ? Just to see the counterpart
z

Zach

05/10/2022, 3:30 PM
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

Thomas

05/10/2022, 3:31 PM
Thanks ! Very clear !
🎉 1
2 Views