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

component.set_input_types() and component.set_input_type() let's user set non-existing inputs #8280

Closed
silvanocerza opened this issue Aug 23, 2024 · 1 comment · Fixed by #8358
Assignees
Labels
P1 High priority, add to the next sprint type:bug Something isn't working
Milestone

Comments

@silvanocerza
Copy link
Contributor

Describe the bug

If a user calls component.set_input_types() or component.set_input_type() in a Component's init method the inputs will be added even if the Component doesn't define a run method that accepts **kwargs.

Expected behavior

Setting an input in a Component init that has a run that doesn't accept **kwargs must fail.

To Reproduce

This sould fail:

@component
class Foo:
    def __init__(self):
        component.set_input_types(self, y=int)

    @component.output_types(output=int)
    def run(self, x: int):
        return {"output": x}


print(Foo())
# <__main__.Foo object at 0x106190500>
# Inputs:
#   - y: int
#   - x: int
# Outputs:
#   - output: int

This should fail too:

@component
class Bar:
    def __init__(self):
        component.set_input_type(self, "y", int)

    @component.output_types(output=int)
    def run(self, x: int):
        return {"output": x}

print(Bar())
# <__main__.Bar object at 0x13998ea80>
# Inputs:
#   - y: int
#   - x: int
# Outputs:
#   - output: int

This is correct instead:

@component
class Baz:
    def __init__(self):
        component.set_input_type(self, "y", int)

    @component.output_types(output=int)
    def run(self, x: int, **kwargs):
        return {"output": x + kwargs.get("y")}

print(Baz())
# <__main__.Baz object at 0x13998ec30>
# Inputs:
#   - y: int
#   - x: int
# Outputs:
#   - output: int
@silvanocerza silvanocerza added the type:bug Something isn't working label Aug 23, 2024
@julian-risch julian-risch added the P1 High priority, add to the next sprint label Aug 26, 2024
@julian-risch julian-risch added this to the 2.5.0 milestone Aug 26, 2024
@silvanocerza silvanocerza modified the milestones: 2.5.0, 2.6.0 Sep 2, 2024
@shadeMe
Copy link
Collaborator

shadeMe commented Sep 11, 2024

We should also raise an error if set_input_types overrides the type of an existing non-kwarg parameter of the run method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 High priority, add to the next sprint type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants