Discussion about null vs []
(for arrays and objects in task arguments)
#209
Labels
JSON Schemas
Editing of WorkflowTask arguments based on JSON Schemas
to be discussed
Not ready to implement
Milestone
Refs:
Let's try to better define the issue.
Note that we'll likely start with a workaround, and then we'll have to make an effort to define the scope of this feature.
The problem in a nutshell:
ROI_table_names=None
orROI_table_names=[]
are both valid options, and the internal function logic leads to two different behaviors. Note that the Python flexibility is coming from theOptional
type hint.null
. The schema only states thatLet's start with a minimal schema
which comes from a Python-function definition like
Since the
ROI_table_names
property in the schema has no default, fractal-server will not set it to anything inWorkflowTask.args
. This means that we start withIf we insert the schema in https://rjsf-team.github.io/react-jsonschema-form (which appears to support much more of the JSON Schema flexibility than what we may aim for), the default
formData
isThis is the same behavior which is currently implemented in fractal-web. The reason for setting this to an empty array by default, even if it's not defined like that in the schema, is that it then allows the user to add/remove items. If we were to let it unset, as in
args = {}
, the user would not be able to add/remove items (*).At this point, the user can add/remove items at will. If they remove all items, the property will be set to
[]
(which is perfectly valid value, as per the schema). Upon saving, this value will be sent to fractal-server, and will be set inWorkflowTask.args
. Up to here, nothing weird.QUESTION 1: how would the user be able to set
ROI_table_names=null
?QUESTION 2: how could the user tell the web client to remove
ROI_table_names
from theargs
object that will be sent to fractal-server?Note that the two questions are the same, because we are removing
null
values fromargs
before calling the PATCH endpoint.As far as I understand, the answer to Q1 and Q2 in https://rjsf-team.github.io/react-jsonschema-form is "this is not possible".
In fractal-web we could make it possible, but then we'd hit Q3: "how would the user be able to set
ROI_table_names=[]
.TLDR: we cannot expose the full flexibility of the Python function through the schema-based form, and we should take decisions like:
The answer is clearly non-trivial..
(*) Alternative possibility: we do let it unset, but when the user clicks "add item to array" we first check if the key
ROI_table_names
exists inargs
. If it does, then we append the new item. If it doesn't, then we first create an empty array and then proceed. This, however, only fixes half of the problem and it is not to be considered an actual solution.The text was updated successfully, but these errors were encountered: