<#1912 Use Airflow task inside dynamic workflow> P...
# flyte-github
a
#1912 Use Airflow task inside dynamic workflow Pull request opened by pingsutw TL;DR A flyte context has an attribute, but dynamic tasks override the current context, so airflow agent cannot get the attribute. With this PR,
_flyte_operator
will return a flyte task if it fails to get the attribute from the flyte context.
Copy code
Traceback (most recent call last):

      File "/usr/local/lib/python3.10/site-packages/flytekit/exceptions/scopes.py", line 206, in user_entry_point
        return wrapped(*args, **kwargs)
      File "/root/flyte-example/airflow_example/bash_operator.py", line 15, in d1
        b = BashOperator(task_id=f"airflow_bash_operator", bash_command="echo hello")
      File "/usr/local/lib/python3.10/site-packages/flytekitplugins/airflow/task.py", line 55, in _flyte_operator
        if hasattr(user_params, "get_original_task") and user_params.get_original_task:
      File "/usr/local/lib/python3.10/site-packages/flytekit/core/context_manager.py", line 296, in __getattr__
        raise AssertionError(f"{attr_name} not available as a parameter in Flyte context - are you in right task-type?")
Type ☑︎ Bug Fix ☐ Feature ☐ Plugin Are all requirements met? ☐ Code completed ☐ Smoke tested ☐ Unit tests added ☐ Code documentation added ☐ Any pending items have an associated Issue Complete description
Copy code
from airflow.operators.bash import BashOperator
from flytekit import workflow, ImageSpec, task, dynamic

new_airflow_plugin = "git+https://github.com/flyteorg/flytekit.git@1775025f7e0db48e0115781e7012493b4aebb79f#subdirectory=plugins/flytekit-airflow"
image_spec = ImageSpec(packages=[new_airflow_plugin, "flytekitplugins-envd"], registry="pingsutw", apt_packages=["git"])


@task(container_image=image_spec)
def t1():
    print("flyte")


@dynamic(container_image=image_spec)
def d1():
    b = BashOperator(task_id=f"airflow_bash_operator", bash_command="echo hello")
    b >> t1()


@workflow
def wf():
    d1()


if __name__ == '__main__':
    wf()
Tracking Issue flyteorg/flyte#3936 Follow-up issue NA flyteorg/flytekit Codecov: 54.71% (-0.01%) compared to c7c5d13 ✅ 29 other checks have passed 29/30 successful checks