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

Inputs type annotation mismatch #1180

Open
zilto opened this issue Oct 15, 2024 · 0 comments
Open

Inputs type annotation mismatch #1180

zilto opened this issue Oct 15, 2024 · 0 comments
Labels
triage label for issues that need to be triaged.

Comments

@zilto
Copy link
Collaborator

zilto commented Oct 15, 2024

This is a scenario that happened to a user and we could surface better errors

Current behavior

Take a look at the type annotations for external_input. The current dataflow definition is valid because the types are deemed equivalent (Any is special, it is both a subclass and super class of all types, including MyClass)

from typing import Any

class MyClass:
   def __init__(self):
      ...

def foo(external_input: MyClass) -> int:
   return 1
   
def bar(external_input: Any) -> int:
   return 2
   
def join_nodes(foo: int, bar: int) -> int:
   return foo + bar

The problem happens when calling Driver.execute(...) and specifying external_input. If the user expects it to take Any and pass a value that's not MyClass, the input validation will say that there's a type mismatch without more details.

inputs = {"external_input": 31} 
dr.execute(["join_nodes"], inputs=inputs)

Additionally, because of the way visualizations are rendered, the two external_input will appear with the same type despite being annotated differently.

Also, the problem is specific to inputs. The following DAG wouldn't raise an error despite the object not matching the annotated type because there's no runtime type validation by default:

from typing import Any

class MyClass:
   def __init__(self):
      ...
      
def internal_input() -> MyClass:
   return 31

def foo(internal_input: MyClass) -> int:
   return 1
   
def bar(internal_input: Any) -> int:
   return 2
   
def join_nodes(foo: int, bar: int) -> int:
   return foo + bar
dr.execute(["join_nodes"])

Potential solutions

  • we could have better errors on input type validation
  • we could warn that nodes are annotated differently but with valid types at Builder.build() time
  • display the different type annotations in the visualization (I suggest against because it would be confusing since it can only be "one type at a time")
@zilto zilto added the triage label for issues that need to be triaged. label Oct 15, 2024
@zilto zilto changed the title Bug Report Inputs type annotation mismatch Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage label for issues that need to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant