cold-teacher-46250
08/26/2025, 4:40 PMjolly-florist-66728
08/26/2025, 4:40 PMjolly-florist-66728
08/26/2025, 4:41 PMmap_task
, use functools.partial
to bind the scalar (fixed) argument, then map over the iterable. For example, if your task is def fn(x: int, y: int) -> int
, you can bind y
as a scalar and map over a list of x
values:
from functools import partial
from flytekit import map_task, task, workflow
@task
def fn(x: int, y: int) -> int:
return x + y
@workflow
def wf(data: list[int], y: int) -> list[int]:
partial_fn = partial(fn, y=y)
return map_task(partial_fn)(x=data)
This approach is documented in the Flyte user guide and examples. Note: do not use a list as a fixed argument in the partial, as this is not supported and will raise an error. See Flyte map tasks documentation and example code.
Would you like more detail or examples for multiple fixed or mapped arguments?
Sources:
- Flyte map tasks documentation
- Flyte map_task example
- Flytekit integration test π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.cold-teacher-46250
08/26/2025, 4:45 PMjolly-florist-66728
08/26/2025, 4:45 PMjolly-florist-66728
08/26/2025, 4:46 PMconditional
construct inside a workflow to set the value of y
based on the length of data
, and then use functools.partial
to bind y
for the map_task
. For example, you can write:
from flytekit import conditional, workflow
from functools import partial
@workflow
def wf(data: list[int]) -> list[int]:
y = (
conditional("choose_y")
.if_((len(data) == 1))
.then(1)
.else_()
.then(2)
)
partial_fn = partial(fn, y=y)
return map_task(partial_fn)(x=data)
This pattern is supported, as Flyte's conditional
can be used to select values based on workflow inputs or task outputs, and the result can be passed to downstream tasks or partials. See Flyte conditionals documentation.
Would you like a more detailed example or explanation of how to use conditional
with map_task
?
Sources:
- Flyte conditionals documentation
- Flyte map_task example π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.cold-teacher-46250
08/26/2025, 4:53 PMjolly-florist-66728
08/26/2025, 4:53 PMjolly-florist-66728
08/26/2025, 4:54 PMlen(data)
directly in a Flyte workflow, data
is a Promise, not a list, so len(data)
is not valid. Instead, you must compute the length in a task, then use the task's output in the conditional. See the Flyte workflows guide and conditional documentation.
Would you like a step-by-step example of how to compute the length in a task and use it in a conditional?
Sources:
- Flyte conditionals documentation
- Flyte workflows guide π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.cold-teacher-46250
08/26/2025, 4:57 PM@task
def is_multiple_dates(dates: list[str]) -> bool:
return len(dates) > 1
so the issue is the int being passed in to the conditional, do i need to create separate tasks that simply return 31 and 0?
padding_minutes = (conditional("padding_minutes_decision")
.if_(multiple_dates_bool.is_false())
.then(31)
.else_()
.then(0)
)
jolly-florist-66728
08/26/2025, 4:57 PMjolly-florist-66728
08/26/2025, 4:58 PMconditional
can return Python primitives (like int
) directly in .then()
and .else_().then()
branches, as shown in the official conditionals example. Your usage is correct:
padding_minutes = (
conditional("padding_minutes_decision")
.if_(multiple_dates_bool.is_false())
.then(31)
.else_()
.then(0)
)
If you encounter an error, ensure that multiple_dates_bool
is the output of a Flyte task and not a raw Python value, and that you use .is_false()
or .is_true()
as shown in the Flyte conditionals documentation.
Would you like a full workflow example demonstrating this pattern?
Sources:
- Flyte conditionals example
- Flyte conditionals documentation π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.cold-teacher-46250
08/26/2025, 5:11 PMstatus
jolly-florist-66728
08/26/2025, 5:11 PMjolly-florist-66728
08/26/2025, 5:12 PMint
in the .then()
or .else_().then()
branchesβFlyte conditionals can return Python primitives like int
directly, as shown in the official Flyte conditionals example. The error is more likely due to how the output of the conditional is being used downstream, or if the conditional is not fully specified (e.g., missing an else_()
branch).
If you are passing the result of the conditional directly to a task or another workflow node, ensure that the receiving function expects an int
and not a Promise or another type. Also, make sure you are not trying to access attributes like .var
on the result of the conditional, as this would only be valid for Promises, not for primitive values.
Would you like to share the full error traceback or the code where you use the result of the conditional?
Sources:
- Flyte conditionals example
- Flyte conditionals documentation π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.cold-teacher-46250
08/26/2025, 5:20 PMjolly-florist-66728
08/26/2025, 5:20 PMjolly-florist-66728
08/26/2025, 5:22 PMfunctools.partial
, when building the execution graph. If you try to use a functools.partial
object as a workflow node or pass it where a Promise is expected, you'll get AttributeError: 'functools.partial' object has no attribute 'var'
(see Flyte workflows guide).
To fix this, only use functools.partial
to bind arguments for tasks you intend to map over with map_task
, and ensure you call the resulting partial with the mapped argument inside the workflow. Do not pass the partial itself as a workflow input or output.
Would you like a step-by-step example of correct usage with map_task
and conditionals?
Sources:
- see Flyte workflows guide π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.cold-teacher-46250
08/26/2025, 5:27 PMpartial_parse_patient_table = (conditional("padding_minutes_decision")
.if_(multiple_dates_bool.is_false())
.then(partial(parse_patient_table, padding_minutes=31))
.else_()
.then(partial(parse_patient_table, padding_minutes=0))
)
map_task(partial_parse_patient_table)(files_to_process)
how would you help debug this error
AttributeError: 'functools.partial' object has no attribute 'var'jolly-florist-66728
08/26/2025, 5:27 PMjolly-florist-66728
08/26/2025, 5:28 PMconditional
expects to return values (like primitives or Promises), not Python objects like functools.partial
. When you return a partial
object from a conditional and pass it to map_task
, Flyte tries to treat it as a node in the workflow graph, but functools.partial
does not have the required attributes (like .var
), leading to AttributeError: 'functools.partial' object has no attribute 'var'
(Flyte conditionals doc).
How to fix:
Instead of returning a partial
from the conditional, use the conditional to select the value for padding_minutes
, then create the partial after the conditional. For example:
padding_minutes = (
conditional("padding_minutes_decision")
.if_(multiple_dates_bool.is_false())
.then(31)
.else_()
.then(0)
)
partial_parse_patient_table = partial(parse_patient_table, padding_minutes=padding_minutes)
map_task(partial_parse_patient_table)(files_to_process)
This way, the conditional returns a primitive, and the partial is constructed with that value, which is supported (see example).
Would you like a more detailed explanation or a full workflow example?
Sources:
- Flyte conditionals doc
- see example π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.cold-teacher-46250
08/26/2025, 5:33 PMjolly-florist-66728
08/26/2025, 5:34 PMjolly-florist-66728
08/26/2025, 5:35 PMcold-teacher-46250
08/26/2025, 5:47 PMpartial_parse_patient_table = partial(parse_patient_table, padding_minutes=padding_minutes)
map_task(partial_parse_patient_table)(files_to_process)
jolly-florist-66728
08/26/2025, 5:48 PMjolly-florist-66728
08/26/2025, 5:50 PMfunctools.partial
for map_task
. The value of padding_minutes
is not a concrete Python int
at workflow compilation timeβit's a Promise object, and functools.partial
does not handle Promises in a Flyte workflow context (see Flyte map_task limitations, Flyte issue #3887).
Correct pattern:
You must pass all dynamic (Promise) values as explicit arguments to the mapped task, not as fixed arguments in a partial. Instead, do:
map_task(parse_patient_table)(files=files_to_process, padding_minutes=padding_minutes)
This way, padding_minutes
(a Promise) is passed as a mapped argument, and Flyte will handle it correctly. Do not use partial
with workflow Promises.
Would you like a full example or further explanation?
Sources:
- Flyte issue #3887 π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.