Exception when using dash_extensions.enrich package with ServersideOutputTransform and diskcache

Hi Dash Community,

I’m using the ServersideOutputTransform to store larger state objects. I also wanted to use long running callbacks.
As soon as I combine the dash_extensions.enrich package and importing the ServersideOutputTransform module the code fails on first page load with an pickling exception.
Exception:

TypeError: cannot pickle '_contextvars.ContextVar' object
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\Users\Matthiak\Projects\Woodside\HydrogenOptimisation\dashvisualisation\.venv\Lib\site-packages\multiprocess\spawn.py", line 122, in spawn_main
    exitcode = _main(fd, parent_sentinel)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\Matthiak\Projects\Woodside\HydrogenOptimisation\dashvisualisation\.venv\Lib\site-packages\multiprocess\spawn.py", line 132, in _main
    self = reduction.pickle.load(from_parent)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\Matthiak\Projects\Woodside\HydrogenOptimisation\dashvisualisation\.venv\Lib\site-packages\dill\_dill.py", line 289, in load
    return Unpickler(file, ignore=ignore, **kwds).load()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\Matthiak\Projects\Woodside\HydrogenOptimisation\dashvisualisation\.venv\Lib\site-packages\dill\_dill.py", line 444, in load
    obj = StockUnpickler.load(self)
          ^^^^^^^^^^^^^^^^^^^^^^^^^

Environment:

  • Windows 11, Python 3.11
  • Packages installed:
    • flask => 3.0.3
    • werkzeug => 3.0.3
    • dash => 2.17.1
    • dash-extensions => 1.0.17

I’m running the application via Flask wrapper through VSCode, so that I see the exception on the command line. It also fails when running directly but then the output in the browser dev window is not helpful.

Minimal code to reproduce:

from dash import DiskcacheManager
from dash_extensions.enrich import DashProxy, Output, Input, State, ALL, no_update, callback, callback_context, Serverside, html, dcc, \
    ServersideOutputTransform
import diskcache

cache = diskcache.Cache("./cache")
background_callback_manager = DiskcacheManager(cache)

app = DashProxy(
			__name__, 
			transforms=[ServersideOutputTransform()], 
			background_callback_manager=background_callback_manager
		)
server = app.server # For Flask

app.layout = html.Div([
	html.Button(id="btn", children="Click"),
	html.Div(id="output-longrunning"),
])

@callback(
	output=Output("output-longrunning", "children"),
	inputs=Input("btn", "n_clicks"),
	background=True
)
def cb_long_running(
	i_trigger
):
    return "Finished"

Can you help please?