Open tcompa opened 1 year ago
Side-comment:
It's likely that slightly different schemas (as the v2 example in https://github.com/fractal-analytics-platform/fractal-tasks-core/issues/375#issuecomment-1559074183) may allow handling this problem slightly differently, because they encode information which is much closer to the Optional keyword. But that's not relevant for the moment, since we are not moving to Pydantic v2 soon.
Re-opening this one, in view of a broader discussion (not to be had today!).
Refs:
205
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 removeROI_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.