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

Ability to access the wrapped function for testing or to import into other programs #1195

Closed
chriddyp opened this issue Apr 14, 2020 · 3 comments
Labels
good first issue suitable for newcomers

Comments

@chriddyp
Copy link
Member

i.e.

@app.callback(...)
def update_graph(value):
    ...

it would be helpful to be able to access or call update_graph unwrapped. Currently, if you call update_graph, you'll call the wrapped version.

Three use cases:

  1. Ability to unit test update_graph
  2. Ability to call update_graph in e.g. Jupyter
  3. Ability to call update_graph in other programs

I believe this violates how decorators work, so we might have to expose some method on the function like .inner so the caller would call e.g. update_graph.inner(value)

@alexcjohnson
Copy link
Collaborator

Actually we don't do anything with the return value of the decorator right now - internal to the decorator we add the wrapped function to the callback map:

self.callback_map[callback_id]["callback"] = add_context

But then we return the wrapped function:

return add_context

I suspect if instead we just return func everyone will be happy 🤞 (aside from any of our own tests that use the wrapped function - those will have to reference app.callback_map instead)

@alexcjohnson
Copy link
Collaborator

Closed in #1839

@shea-parkes
Copy link

Just dropping a note a couple years later for others that might land here:

We were actually expecting that we'd have to do myfunc.__wrapped__ in our unit tests type work. But since the current dash.callback code returns the original func (instead of the wrapped version it created), you can just work directly with the function as-if it wasn't decorated with dash.callback().

We basically overthought things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue suitable for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants