exception for mandatory parameters in plugins and macros

Solved!
NN
exception for mandatory parameters in plugins and macros

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

0 Kudos
1 Solution
AlexT
Dataiker

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. 

View solution in original post

0 Kudos
9 Replies
NN
Author

Edited..

0 Kudos
AlexT
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.

0 Kudos
NN
Author

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

0 Kudos
AlexT
Dataiker

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. 

0 Kudos
NN
Author

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

0 Kudos
akshaykatre
Level 1

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? 

0 Kudos
jvijayakumar2
Level 3

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

 

0 Kudos
NN
Author

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. 

0 Kudos
jvijayakumar2
Level 3

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. 

0 Kudos