exception for mandatory parameters in plugins and macros

NN
NN Neuron, Registered, Neuron 2022, Neuron 2023 Posts: 145 Neuron

Hi All.
Editing my question to help better understand.

In a custom recipe or custom macro
We have the option to define a parameter as mandatory "mandatory":true

Can someone please help check if this option works properly for them in their custom recipe/macro.
i.e. a value for the parameter must be supplied in order to use the recipe/macro.

I am trying to check for v 8.0.5 and above.

Thanks

Best Answer

  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,226 Dataiker
    edited July 17 Answer ✓

    Testing this "required": true works for inputRoles/outputRoles.

    However, for params using mandatory or required has no effect within recipe component. You could handle this in recipe code directly when reading the parameters here is an example of how this is done from another Plugin recipe

    text_column_name = recipe_config.get('text_column_name', None)
    if text_column_name is None:
        raise ValueError("You did not choose a text column.")
    
    n_sentences = recipe_config.get('n_sentences', None)
    if n_sentences is None:
        raise ValueError("You did not set a number of sentences.")
    
    method = recipe_config.get('method', None)
    if method is None:
        raise ValueError("You did not choose a summarization method.")

    Let me know if this helps.

Answers

  • NN
    NN Neuron, Registered, Neuron 2022, Neuron 2023 Posts: 145 Neuron
  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,226 Dataiker

    The "mandatory" flag does not apply to macros and it will only be used with other plugin components. We have captured this use case and the desire to make certain macro params/fields mandatory and is under review by our product team.

  • NN
    NN Neuron, Registered, Neuron 2022, Neuron 2023 Posts: 145 Neuron

    Thanks @AlexT

    One Request, Just to help me out can you please check if the Mandatory option is working properly in other plugin components like a Component Recipe?
    I faced an issue where it didnt work even on a custom recipe on V9

  • NN
    NN Neuron, Registered, Neuron 2022, Neuron 2023 Posts: 145 Neuron

    Thanks @AlexT

    With so many parameter examples and documents mentioning that option i somehow always assumed that it works.
    We shall change all our codes to raise exceptions instead

  • akshaykatre
    akshaykatre Registered Posts: 4 ✭✭✭✭

    Thanks @NN
    , @AlexT
    ; I noticed this feature and was happy to have found the answer
    Just curious, what is the purpose of mandatory/ required in parameters?

  • jvijayakumar2
    jvijayakumar2 Partner, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 30 Partner

    I have the same question. The documentation says it can also be used for parameters. But I can still use a plugin recipe without supplying a field that is set to mandatory.

    https://doc.dataiku.com/dss/latest/plugins/reference/params.html#describing-parameters

  • NN
    NN Neuron, Registered, Neuron 2022, Neuron 2023 Posts: 145 Neuron

    hi @jvijayakumar2
    & @akshaykatre

    If i remember correctly i think that the mandatory = True will just just show some indication in red if a parameter is mandatory and has not been defined. But it still allows the recipe to run even if a value has not been passed to a mandatory parameter.

    I think the way it works now does make sense
    as Alex suggested it is better to keep checks for mandatory fields in the recipes code so that you can have complex conditions if needed.

  • jvijayakumar2
    jvijayakumar2 Partner, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 30 Partner

    You are right that we can add checks for the mandatory field in the recipe code like @AlexT
    has written.
    But the documentation seems to say that the component can't be used without supplying the mandatory fields. Also, the red indication doesn't happen unless I enter a value in a mandatory field and remove it.

Setup Info
    Tags
      Help me…