plotly / plotly/dash

callback named arg inconsistency: `input` vs `inputs`

Open
#1,777 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

Describe your context

Python 3.9.6

dash                      2.0.0
dash-bootstrap-components 0.13.1
dash-core-components      2.0.0
dash-html-components      2.0.0
dash-table                5.0.0

Describe the bug

When implementing a callback with named argument input (as exemplified in the dash 2.0.0 release notes), the callback is never triggered (akin to a silent failure). This is because only named argument inputs is recognized, and input is ignored.

When also providing the state named argument, the following exception is raised:

Traceback (most recent call last):
...
  File (file and function of my own code)
    @app.long_callback(
  File "~/miniconda3/envs/passoff/lib/python3.9/site-packages/dash/dash.py", line 1111, in long_callback
    ) = handle_grouped_callback_args(_args, _kwargs)
  File "~/miniconda3/envs/passoff/lib/python3.9/site-packages/dash/dependencies.py", line 308, in handle_grouped_callback_args
    inputs_state = extract_grouped_input_state_callback_args(flat_args, kwargs)
  File "~/miniconda3/envs/passoff/lib/python3.9/site-packages/dash/dependencies.py", line 250, in extract_grouped_input_state_callback_args
    raise ValueError(
ValueError: The state keyword argument may not be provided without the input keyword argument

The key part is the final line which references the input keyword argument, which is misleading/incorrect given the actual behavior.

Expected behavior

Following the given example should result in a functional callback that is triggered by the specified Inputs. Also, related errors should correctly reflect that the needed keyword argument.

Given the analogy of output=Output(...) and state=State(...), I'd expect the named argument for Input to be input, not inputs.

Screenshots

INCORRECT: https://community.plotly.com/t/dash-2-0-prerelease-candidate-available/55861#breaking-changes-8
dash-2 0 0-release-notes

CORRECT: https://dash.plotly.com/flexible-callback-signatures

RELATED PACKAGE CODE:

dash/dependencies.py lines 244 through 255

def extract_grouped_input_state_callback_args(args, kwargs):
    if "inputs" in kwargs:
        return extract_grouped_input_state_callback_args_from_kwargs(kwargs)

    if "state" in kwargs:
        # Not valid to provide state as kwarg without input as kwarg
        raise ValueError(
            "The state keyword argument may not be provided without "
            "the input keyword argument"
        )

    return extract_grouped_input_state_callback_args_from_args(args)

dash/dependencies.py lines 178 through 181

def extract_grouped_input_state_callback_args_from_kwargs(kwargs):
    input_parameters = kwargs["inputs"]
    if isinstance(input_parameters, DashDependency):
        input_parameters = [input_parameters]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in dash/dependencies.py, especially extract_grouped_input_state_callback_args and extract_grouped_input_state_callback_args_from_kwargs, which the issue identifies. Inspect how named callback arguments are parsed and how the related ValueError is produced. Done means the documented singular input form triggers callbacks and related errors use the correct keyword name.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.