Open jluethi opened 5 months ago
What would be very nice here: If the user enters text in both fields, json validation fails. I'm not sure if that's feasible? And how we could set up a Pydantic model that can reliably be parsed into that?
I would split this discussion into three parts:
Points 1 and 2 are the ones which I think can already start and be discussed in this issue (or in a mirror issue in fractal-web). We should collect a few examples where either/or conditions are only enforced within Python, and look for the appropriate form of the more strict JSON Schema - so that we can then start playing with the form generator.
3. My first guess is that Pydantic may not be flexible enough
Just for the record, a typical solution is to use two models for the two different scenarios (as in https://stackoverflow.com/questions/78243337/pydantic-model-with-fields-that-have-dependent-allowable-values).
Brainstorming issue.
Can we improve what kind of json manifests are built to handle the following 2 cases better? Both examples of the Cellpose
CellposeChannel1InputModel
:1. either/or logic
What if we have 2 values and a user can only select 1? See "user should either specify Wavelength ID or Label, but if they specify both, the Pydantic model validation fails
=> How could we display this better? One option that won't look so good: Have a dropdown for "how to select channel" with wavelength ID & label. And a single "value" field.
What would be very nice here: If the user enters text in both fields, json validation fails. I'm not sure if that's feasible? And how we could set up a Pydantic model that can reliably be parsed into that?
Same would apply to only setting lower & upper percentile, or lower & upper bound, but not both. We validate on the Python side, but can't easily expose this in the interface.
2. conditional fields
If "default" is selected for normalize type, a user shouldn't be able to enter percentiles or bounds. If they select custom, those fields should "show up". Again, not sure if we can specify this in a json model and how we'd get from Pydantic reliably to that json.
One thing we discussed and discarded: The server does not run the task to try whether inputs would validate. Any improvement here cannot remove this separation. So it would need to work in json schemas that we can reliably generate from Python code, potentially with advanced features for how the developer sets them (see discussion here: https://github.com/fractal-analytics-platform/fractal-tasks-core/issues/755)