Skip to content

Feature request: delayed validation #643

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

Closed
0zeroth opened this issue Mar 11, 2019 · 2 comments
Closed

Feature request: delayed validation #643

0zeroth opened this issue Mar 11, 2019 · 2 comments

Comments

@0zeroth
Copy link

0zeroth commented Mar 11, 2019

Validation is awesome, but if all the components are not defined upfront it must be disabled (eg when creating multi-page / multi-file apps).

It is possible to monkey-patch delayed validation. An example is below, but since the introduction of multi-output it is probably not correct. I find this extremely useful, as I always get the @app.callback strings wrong, and even though immediate validation is best, this is much better than nothing.

Perhaps this could be added as a feature! (I of course leave the decision to accept/reject this proposal in your capable hands!)

import dash

_old_validate = dash.Dash._validate_callback
_list = []


def new_validate(self, output, inputs, state):
    _list.append(tuple((output, inputs, state)))

dash.Dash._validate_callback = new_validate


def validate_callbacks(app):
    from dash._utils import create_callback_id as _create_callback_id
    old_map = app.callback_map
    app.callback_map = {} # Monkey patch to trick Dash from raising DuplicateCallbackOutput
    for output, inputs, state in _list:
        _old_validate(app, output, inputs, state)
        callback_id = _create_callback_id
    app.callback_map = old_map

app = dash.Dash(__name__)

# After defining all the callbacks ...

validate_callbacks(app)
app.run_server(**CONFIG)
@ned2
Copy link
Contributor

ned2 commented Mar 11, 2019

I very much agree, and in fact, have just submitted a proposed PR for doing this: #644.

I ended up taking the same basic approach as yours, but with some extra logic for detecting duplicated Outputs in callbacks (including handling multi-output callbacks). Feedback welcome!

@alexcjohnson
Copy link
Collaborator

Combining this with #519

HammadTheOne pushed a commit to HammadTheOne/dash that referenced this issue May 28, 2021
HammadTheOne pushed a commit that referenced this issue Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants