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

bool(LazySelectSequence) can return None #43977

Open
2 tasks done
johncmerfeld opened this issue Nov 13, 2024 · 1 comment · May be fixed by #43978
Open
2 tasks done

bool(LazySelectSequence) can return None #43977

johncmerfeld opened this issue Nov 13, 2024 · 1 comment · May be fixed by #43978
Labels
area:core kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet

Comments

@johncmerfeld
Copy link

Apache Airflow version

2.10.3

If "Other Airflow 2 version" selected, which one?

No response

What happened?

The downstream effect is that

  • when doing an Xcom pull for a group of task IDs
  • when the returned list is empty
  • an exception is raised because Jinja fails to render the template
[2024-11-13, 18:05:16 UTC] {abstractoperator.py:780} ERROR - Exception rendering Jinja template for task '...'
Traceback (most recent call last):
  File "airflow/models/abstractoperator.py", line 772, in _do_render_template_fields
    rendered_content = self.render_template(
                       ^^^^^^^^^^^^^^^^^^^^^
  File "airflow/template/templater.py", line 171, in render_template
    return self._render(template, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "airflow/models/abstractoperator.py", line 727, in _render
    return super()._render(template, context, dag=dag)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "airflow/template/templater.py", line 126, in _render
    return render_template_as_native(template, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "airflow/utils/helpers.py", line 306, in render_template_as_native
    return render_template(template, cast(MutableMapping[str, Any], context), native=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "airflow/utils/helpers.py", line 295, in render_template
    return jinja2.nativetypes.native_concat(nodes)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "jinja2/nativetypes.py", line 25, in native_concat
    head = list(islice(values, 2))
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "<template>", line 24, in root
  File "jinja2/async_utils.py", line 45, in wrapper
    return normal_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "jinja2/filters.py", line 1352, in sync_do_list
    return list(value)
           ^^^^^^^^^^^
  File "jinja2/filters.py", line 1492, in sync_do_map
    if value:
       ^^^^^
TypeError: __bool__ should return bool, returned NoneType

What you think should happen instead?

In this case an empty list should be returned

The root cause is that LazySelectSequence's __bool__ method is not airtight. I don't understand the internals well enough to know why this is so, but this is clearly an internal error, given a valid template:

"{{  ti.xcom_pull(task_ids=['a', 'b', 'c'], key='return_value')  | map(attribute=0) | list }}"

How to reproduce

  • Use a template like this to pull the return values from a list of tasks: "{{ ti.xcom_pull(task_ids=['a', 'b', 'c'], key='return_value') | map(attribute=0) | list }}"
  • Ensure that all of those tasks Skip or otherwise do not return a value

Operating System

Ubuntu 24.04.1

Versions of Apache Airflow Providers

No response

Deployment

Virtualenv installation

Deployment details

No response

Anything else?

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@johncmerfeld johncmerfeld added area:core kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet labels Nov 13, 2024
Copy link

boring-cyborg bot commented Nov 13, 2024

Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:core kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant