Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recap on up-to-date priorities #218

Closed
5 tasks done
tcompa opened this issue Jun 23, 2023 · 1 comment · Fixed by #220
Closed
5 tasks done

Recap on up-to-date priorities #218

tcompa opened this issue Jun 23, 2023 · 1 comment · Fixed by #220

Comments

@tcompa
Copy link
Collaborator

tcompa commented Jun 23, 2023


Re: #209

Consider this schema:

{
            "title": "NapariWorkflowsInput",
            "description": "A value of the ``input_specs`` argument in ``napari_workflows_wrapper``.",
            "type": "object",
            "properties": {
              "type": {
                "title": "Type",
                "enum": [
                  "image",
                  "label"
                ],
                "type": "string",
                "description": "Input type (supported: ``image`` or ``label``)."
              },
              "label_name": {
                "title": "Label Name",
                "type": "string",
                "description": "Label name (for label inputs only)."
              },
              "channel": {
                "$ref": "#/definitions/Channel",
                "description": "Channel object (for image inputs only)."
              }
            },
            "required": [
              "type"
            ]
          }

where channel is not required.
When we prepare the payload for the server, if the user does not enter any attribute for channel, then the (unstripped) data have channel={}. This leads to errors downstream, because later on the fractal tasks try to validate the channel content ({}) and it is not valid (because it lacks some required arguments). Note that ajv does not complain, and lets the validation go through. This is because this kind of "validation" is Python-only, and it is not part of the JSON Schema.

Question: can we modify our removeEmptyObjectsAndArrays function (the one leading to stripped data to be sent to the server) and make sure that all empty objects {} are replaced by null, and then stripped from args. This should happen recursively, and not only for first-level arguments.

I would say that the same behavior is expected for empty arrays [].

Current status:

/**
* Remove empty objects and arrays from an object and its nested objects
* @param obj
* @returns {*}
*/
function removeEmptyObjectsAndArrays(obj) {
Object.keys(obj).forEach(key => {
if (obj[key] && typeof obj[key] === 'object') {
// Next line would enable removing empty objects and arrays from nested objects
// removeEmptyObjectsAndArrays(obj[key]);
if (Object.keys(obj[key]).length === 0) delete obj[key];
}
});
return obj;
}

I currently don't remember why we commented the line enabling recursive behaviors. I am not aware of any tasks where we typically want to pass an empty object or array and that should be preferred over a null.

@jluethi
Copy link
Collaborator

jluethi commented Jun 23, 2023

Sounds great, fully agree with these priorities!

If we have those, finding additional ways to make the nested parameters take less space would be great! Smaller descriptions, descriptions that are hidden by default (or only show e.g. first 10 words), some iterations on layout given e.g. the Create OME Zarr task would all be great. We can deploy without, but let's iterate a bit on the display of it :)

@rkpasia rkpasia linked a pull request Jun 26, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants