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

[BUG] Flytkit Named Tuples cannot access be accessed if there is only one attribute #2793

Closed
brandon-segal opened this issue Aug 19, 2022 · 3 comments
Assignees
Labels

Comments

@brandon-segal
Copy link

Description:

In Flytekit there is no way to mock a named tuple that only has a single member. Mocking a situation like the following results in a AttributeError: 'Promise' object has no attribute 'uri' error.

class GenerateOutputs(NamedTuple):
        uri: str
    
@reference_task(
    ...
)
def generate(
    input:str 
) -> GenerateOutputs:
    ... 
    
@workflow
def my_wf(
   input="default_input"
) -> str:
    output = generate(
      input:str=input
    )
    return output.uri

class TestNamedTuple(TestCase):
    def test_run_workflow(self):
        with task_mock(generate) as fake_generate:
            fake_generate.return_value = GenerateOutputs(uri="test_uri")
            uri = my_wf()
            self.assertIsNotNone(uri)

Ideally we would be able to do something like the following which we can do when the NamedTuple has two attributes:

from typing import NamedTuple
from unittest import TestCase
from flytekit.testing import task_mock
from flytekit import workflow,reference_task

class GenerateOutputs(NamedTuple):
    uri: str
    other_thing:str

@reference_task(
    ...
)
def generate(
    input:str 
) -> GenerateOutputs:
    ... 

@workflow
def my_wf(
    input:str="default_input"
) -> str:
    output = generate(
        input=input
    )
    # Could similarly unpack the tuple and just return the uri 
    return output.uri


class TestNamedTuple(TestCase):
    def test_run_workflow(self):
        with task_mock(generate) as fake_generate:
            fake_generate.return_value = GenerateOutputs(uri="test_uri",other_thing="test")
            uri = my_wf()
            self.assertIsNotNone(uri)
@welcome
Copy link

welcome bot commented Aug 19, 2022

Thank you for opening your first issue here! 🛠

@eapolinario eapolinario added this to the 1.2.0-candidate milestone Aug 19, 2022
@cosmicBboy cosmicBboy removed this from the 1.3.0-candidate milestone Jan 23, 2023
@github-actions
Copy link

Hello 👋, This issue has been inactive for over 9 months. To help maintain a clean and focused backlog, we'll be marking this issue as stale and will close the issue if we detect no activity in the next 7 days. Thank you for your contribution and understanding! 🙏

@github-actions github-actions bot added the stale label Oct 21, 2023
@wild-endeavor
Copy link
Contributor

Something similar to this will soon be possible. We still haven't figured out the namedtuple issue yet, but you should be able to bind to dataclass components soon. #4232

Please re-open if this is not sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants