fractal-analytics-platform / fractal-tasks-core

Main tasks for the Fractal analytics platform
https://fractal-analytics-platform.github.io/fractal-tasks-core/
BSD 3-Clause "New" or "Revised" License
14 stars 6 forks source link

To review: Optional arrays/objects should not have side effects #439

Open tcompa opened 1 year ago

tcompa commented 1 year ago

EDIT: The most compelling specific issue is now part of #448. This issue is now to track the broader discussion on how to proceed regarding:

  1. scope setting: which use cases will be supported in fractal-web? Where will this information be documented?
  2. fractal_tasks_core development: will there be an automated check of scope compliance
  3. custom task packages: the requirements from point 1 should be made extremely clear

(coming from discussions with @rkpasia)

Consider this task

def task_function(x: Optional[list[str]] = None) -> str:
    if x is None:
        return "A"
    elif len(x) == 0:
        return "B"
    else:
        return "C"

which has a different behavior for x=None and x=[]. I think this is a bad practice, and should be avoided.

The reason for this issue comes from https://github.com/fractal-analytics-platform/fractal-web/issues/205. Depending on how we proceed in fractal-web, it's not clear whether setting x=[] will be allowed. In general, it's better to stay on the safe side and make sure that tasks are robust.

tcompa commented 1 year ago

Note: this issue is not yet well defined, as it largely depends on how things evolve in fractal-web. It's also possible that it won't be relevant for 0.10.0, if everything appears to work "as is", and we'll tackle it later.

(also: I edited the example above, for clarity)

tcompa commented 1 year ago

A relevant example is currently in copy_ome_zarr:

We can use this as a good (and very simple) example for further discussions/tests.

tcompa commented 1 year ago

Related to this, and to https://github.com/fractal-analytics-platform/fractal-web/issues/218:

If there is no such case (or if it is not used often), then we can proceed as in https://github.com/fractal-analytics-platform/fractal-web/issues/218. Otherwise we need to review this issue.

tcompa commented 1 year ago

Tasks I'm reviewing (check mark means I did not identify any scenario in which [] or {} is a typical/useful input).

tcompa commented 1 year ago

Re: copy_ome_zarr.py This is an at-risk task, due to https://github.com/fractal-analytics-platform/fractal-tasks-core/issues/439#issuecomment-1603742903. It would become an issue if someone wants to use different ROI tables than the default ones.

Re: create_ome_zarr_multiplex.py:

Re: create_ome_zarr.py

Re: napari_workflows_wrapper

Summary:

tcompa commented 1 year ago

Addendum:

Re: lib_input_models.py

Re: lib_channels.py

tcompa commented 1 month ago

cc @lorenzocerrone