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

When passing the 'False' value to the parameters of a decorated dag function I get this traceback #22843

Closed
1 of 2 tasks
tronlightracer opened this issue Apr 7, 2022 · 1 comment · Fixed by #22964
Closed
1 of 2 tasks
Labels
area:core kind:bug This is a clearly a bug

Comments

@tronlightracer
Copy link

tronlightracer commented Apr 7, 2022

Apache Airflow version

2.2.3

What happened

When passing the False value to a decorated dag function I get this traceback below. Also the default value is not shown when clicking 'trigger dag w/ config'.

[2022-04-07, 20:08:57 UTC] {standard_task_runner.py:52} INFO - Started process 2170 to run task
[2022-04-07, 20:08:57 UTC] {standard_task_runner.py:76} INFO - Running: ['airflow', 'tasks', 'run', 'check_ui_config', 'value_consumer', 'manual__2022-04-07T20:08:56.914410+00:00', '--job-id', '24', '--raw', '--subdir', 'DAGS_FOLDER/check_ui_config.py', '--cfg-path', '/tmp/tmpww9euksv', '--error-file', '/tmp/tmp7kjdfks5']
[2022-04-07, 20:08:57 UTC] {standard_task_runner.py:77} INFO - Job 24: Subtask value_consumer
[2022-04-07, 20:08:57 UTC] {logging_mixin.py:109} INFO - Running <TaskInstance: check_ui_config.value_consumer manual__2022-04-07T20:08:56.914410+00:00 [running]> on host a643f8828615
[2022-04-07, 20:08:57 UTC] {taskinstance.py:1700} ERROR - Task failed with exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 1329, in _run_raw_task
    self._execute_task_with_callbacks(context)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 1418, in _execute_task_with_callbacks
    self.render_templates(context=context)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 1992, in render_templates
    self.task.render_template_fields(context)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 1061, in render_template_fields
    self._do_render_template_fields(self, self.template_fields, context, jinja_env, set())
  File "/usr/local/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 1074, in _do_render_template_fields
    rendered_content = self.render_template(content, context, jinja_env, seen_oids)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 1125, in render_template
    return tuple(self.render_template(element, context, jinja_env) for element in content)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 1125, in <genexpr>
    return tuple(self.render_template(element, context, jinja_env) for element in content)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 1116, in render_template
    return content.resolve(context)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/param.py", line 226, in resolve
    raise AirflowException(f'No value could be resolved for parameter {self._name}')
airflow.exceptions.AirflowException: No value could be resolved for parameter test
[2022-04-07, 20:08:57 UTC] {taskinstance.py:1267} INFO - Marking task as FAILED. dag_id=check_ui_config, task_id=value_consumer, execution_date=20220407T200856, start_date=20220407T200857, end_date=20220407T200857
[2022-04-07, 20:08:57 UTC] {standard_task_runner.py:89} ERROR - Failed to execute job 24 for task value_consumer
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/airflow/task/task_runner/standard_task_runner.py", line 85, in _start_by_fork
    args.func(args, dag=self.dag)
  File "/usr/local/lib/python3.9/site-packages/airflow/cli/cli_parser.py", line 48, in command
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/airflow/utils/cli.py", line 92, in wrapper
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/airflow/cli/commands/task_command.py", line 298, in task_run
    _run_task_by_selected_method(args, dag, ti)
  File "/usr/local/lib/python3.9/site-packages/airflow/cli/commands/task_command.py", line 107, in _run_task_by_selected_method
    _run_raw_task(args, ti)
  File "/usr/local/lib/python3.9/site-packages/airflow/cli/commands/task_command.py", line 180, in _run_raw_task
    ti._run_raw_task(
  File "/usr/local/lib/python3.9/site-packages/airflow/utils/session.py", line 70, in wrapper
    return func(*args, session=session, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 1329, in _run_raw_task
    self._execute_task_with_callbacks(context)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 1418, in _execute_task_with_callbacks
    self.render_templates(context=context)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 1992, in render_templates
    self.task.render_template_fields(context)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 1061, in render_template_fields
    self._do_render_template_fields(self, self.template_fields, context, jinja_env, set())
  File "/usr/local/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 1074, in _do_render_template_fields
    rendered_content = self.render_template(content, context, jinja_env, seen_oids)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 1125, in render_template
    return tuple(self.render_template(element, context, jinja_env) for element in content)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 1125, in <genexpr>
    return tuple(self.render_template(element, context, jinja_env) for element in content)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 1116, in render_template
    return content.resolve(context)
  File "/usr/local/lib/python3.9/site-packages/airflow/models/param.py", line 226, in resolve
    raise AirflowException(f'No value could be resolved for parameter {self._name}')
airflow.exceptions.AirflowException: No value could be resolved for parameter test

What you think should happen instead

I think airflow should be able to handle the False value when passing it as a dag param.

How to reproduce

from airflow.decorators import dag, task
from airflow.models.param import Param

from datetime import datetime, timedelta


@task
def value_consumer(val):
    print(val)


@dag(
    start_date=datetime(2021, 1, 1),
    schedule_interval=timedelta(days=365, hours=6)
)
def check_ui_config(test):
    value_consumer(test)
    

the_dag = check_ui_config(False)

Operating System

Docker (debian:buster)

Versions of Apache Airflow Providers

No response

Deployment

Astronomer

Deployment details

Astro cli with this image:
quay.io/astronomer/ap-airflow-dev:2.2.3-2

Anything else

Screenshot from 2022-04-07 14-13-43

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@tronlightracer tronlightracer added area:core kind:bug This is a clearly a bug labels Apr 7, 2022
@MatrixManAtYrService
Copy link
Contributor

MatrixManAtYrService commented Apr 7, 2022

This appears to be the case for any falsey value. Consider this dag:

@dag
def paramstuff(x, a=Param(2, minimum=0)):

    @task
    def add(one, other):
        print(one + other)

    add(x, a)


the_dag = paramstuff(3)  # two params: x,a
# add says 5 unless you specify different params at run time

# the_dag = paramstuff(0)  # one dag param: a
# add says: AirflowException: No value could be resolved for parameter x

I'm not sure how we should treat positional args being passed into @dag decorated functions (I'm tempted to say that they shouldn't interact with DagParams at all, leave that to the kwargs). But whatever we do, it probably shouldn't depend on whether those values are falsey.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants