Hello all I'm having an issue when trying to use r...
# ask-the-community
Hello all I'm having an issue when trying to use reference tasks... When building image, I'm getting this error:
'ReferenceTask' object has no attribute '_task_function'
... Can someone help me? I would be very appreciated
I'm using some tasks to test This is an example:
Copy code
from flytekit import task

def task_example(n: int) -> int:
    Simple example task for library building.
        n (int): name of the parameter for the task will be derived from the name of the input variable
            the type will be automatically deduced to be Types.Integer

        int: The label for the output will be automatically assigned and type will be deduced from the annotation


    return n * n
And I'm referencing like this:
Copy code
from flytekit import reference_task

def task_example(n: int)->int:
Seems odd - do you have bigger stack trace
I think we understood what was the problem We are using a custom class as return in one of the referenced tasks. But I thought that it wont be needed to recreate in other project, if we are using reference class...
Even when we added the custom class, the error keeps happening...
@Victor Gustavo da Silva Oliveira, if you could share the actual code snippet and stack trace, that'd be helpful to find the source of the error.
Sorry it took so long It is happening in a colleague's task Here it is:
Copy code
Traceback (most recent call last):
  File "/home/jbudke/miniforge3/envs/dedup/bin/pyflyte", line 8, in <module>
  File "/home/jbudke/.local/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/jbudke/.local/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/jbudke/.local/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jbudke/.local/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jbudke/.local/lib/python3.8/site-packages/click/core.py", line 1651, in invoke
    cmd_name, cmd, args = self.resolve_command(ctx, args)
  File "/home/jbudke/.local/lib/python3.8/site-packages/click/core.py", line 1698, in resolve_command
    cmd = self.get_command(ctx, cmd_name)
  File "/home/jbudke/miniforge3/envs/dedup/lib/python3.8/site-packages/flytekit/clis/sdk_in_container/run.py", line 607, in get_command
    entity = load_naive_entity(module, exe_entity, project_root)
  File "/home/jbudke/miniforge3/envs/dedup/lib/python3.8/site-packages/flytekit/clis/sdk_in_container/run.py", line 447, in load_naive_entity
  File "/home/jbudke/miniforge3/envs/dedup/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/jbudke/Área de Trabalho/image-intelligence/dsc-image-intelligence/src/flyte_tasks/workflows/image_workflow.py", line 13, in <module>
    def image_workflow(
  File "/home/jbudke/miniforge3/envs/dedup/lib/python3.8/site-packages/flytekit/core/workflow.py", line 739, in workflow
    return wrapper(_workflow_function)
  File "/home/jbudke/miniforge3/envs/dedup/lib/python3.8/site-packages/flytekit/core/workflow.py", line 734, in wrapper
  File "/home/jbudke/miniforge3/envs/dedup/lib/python3.8/site-packages/flytekit/core/workflow.py", line 614, in compile
    workflow_outputs = exception_scopes.user_entry_point(self._workflow_function)(**input_kwargs)
  File "/home/jbudke/miniforge3/envs/dedup/lib/python3.8/site-packages/flytekit/exceptions/scopes.py", line 198, in user_entry_point
    return wrapped(*args, **kwargs)
  File "/home/jbudke/Área de Trabalho/image-intelligence/dsc-image-intelligence/src/flyte_tasks/workflows/image_workflow.py", line 41, in image_workflow
    all_samples = map_task(
  File "/home/jbudke/miniforge3/envs/dedup/lib/python3.8/site-packages/flytekit/core/map_task.py", line 274, in map_task
    return MapPythonTask(task_function, concurrency=concurrency, min_success_ratio=min_success_ratio, **kwargs)
  File "/home/jbudke/miniforge3/envs/dedup/lib/python3.8/site-packages/flytekit/core/tracker.py", line 35, in __call__
    o = super(InstanceTrackingMeta, cls).__call__(*args, **kwargs)
  File "/home/jbudke/miniforge3/envs/dedup/lib/python3.8/site-packages/flytekit/core/map_task.py", line 58, in __init__
    _, mod, f, _ = tracker.extract_task_module(python_function_task.task_function)
  File "/home/jbudke/miniforge3/envs/dedup/lib/python3.8/site-packages/flytekit/core/python_function_task.py", line 156, in task_function
    return self._task_function
AttributeError: 'ReferenceTask' object has no attribute '_task_function'
Are you using the referenced task in a map task?
Is it possible for you to share a redacted code snippet?
Yes, the idea is to use the referenced task as a mapped task due to the size of the dataset it handles
I'll try to update the code as soon as I can
But the general idea is to use the referenced task, which uses a model to do some image predictions in a map task for better performance
Looks like a bug. cc @Eduardo Apolinario (eapolinario) Code:
Copy code
from flytekit import map_task, reference_task, workflow

def t1(x: int) -> int:

def wf(x: list[int] = [3, 2]):
    return map_task(t1)(x=x)
Copy code
Failed with Unknown Exception <class 'AttributeError'> Reason: 'ReferenceTask' object has no attribute '_task_function'
I agree. @Samhita Alla, can you open a gh issue?
I do not think this is a bug, I think this is a feature request
And this is a hard one