flyte icon indicating copy to clipboard operation
flyte copied to clipboard

[BUG] Regression when registering Empty Default complex values for parameters after Union/Sumtype support

Open kumare3 opened this issue 4 years ago • 2 comments

Describe the bug

PR https://github.com/flyteorg/flytepropeller/pull/373 added support for union types, but also removed an extra check that allows having None values as default values for types like collections. This change introduced a regression, that affects empty defaults for a workflow parameter. Example

@workflow
def wf2m(i: Dict[str, int] = {}) -> Dict[str, int]:
    return t2(i=i)

OR

@workflow
def wf(l: List[str] = []) -> List[str]:
    return t1(l=l)

Compilation now fails. This is because, in protobuf to represent an empty type the only option is to support empty messages.

The empty type check happens in Flyteadmin here Note, that the default value is not None, and the guessed type for an empty list - [] is of type collection:None After the PR#373 the isVoid check was removed, which implies that collection:None is no longer castable to collection:int

I think one of the problems is guessing the type on the RHS, but there does not seem to be a better option

Expected behavior

Users should be able to use l = [] or m = {} as default values

Additional context to reproduce

Simple example that can fail

from flytekit import workflow, task
from typing import List, Dict

@task
def t1(l: List[str]) -> List[str]:
    return l


@workflow
def wf(l: List[str] = []) -> List[str]:
    return t1(l=l)


@task
def t2(i: Dict[str, int]) -> Dict[str, int]:
    return i

@workflow
def wf2m(i: Dict[str, int] = {}) -> Dict[str, int]:
    return t2(i=i)

Example generated struct for Default

parameters {
  key: "i"
  value {
    var {
      type {
        map_value_type {
          simple: INTEGER
        }
      }
      description: "i"
    }
    default {
      map {
      }
    }
  }

Screenshots

No response

Are you sure this issue hasn't been raised already?

  • [X] Yes

Have you read the Code of Conduct?

  • [X] Yes

kumare3 avatar Apr 27 '22 20:04 kumare3

FYI a user reported also having to change:

Input(
        Types.String,
        help='State date string',
        default=None,
    )

to default='' instead. It is possible that having None as the default value broadly triggers this issue.

convexquad avatar May 04 '22 21:05 convexquad

I see the PR is in which is good, but FYI, it's impossible to even send an empty string using the UI. So the work-around of default='' unfortunately only works if launching programmatically.

DobsX avatar May 06 '22 19:05 DobsX