Bokeh server keeps breaking saying AttributeError: 'Document' object has no attribute '_theme'

Recently have been using Panel from the Holoviz ecosystem to build a dashboard, and have been experiencing almost regular crashes from Bokeh’s end over the exact same error: AttributeError: 'Document' object has no attribute '_theme'.

I wish I could say there was something specific I was doing during tests or usage to trigger this, but the truth is it occurs sporadically and very very unpredictably, crashing the entire server and requiring a restart. There is a common denominator, however, that the Attribute error happens when I change pages where each page represents a separate grouping of Bokeh plots. However, it’s like a coin flip because sometimes it works no problem.

I was wondering if anyone had come across such an error and how one could mitigate it, as there is no way I can deploy to production with the instability present now. Some details however, the error originates when attempting to “render” a Holoviews (import holoviews as hv) chart into a Bokeh one using hv.render(plot_object).

This is the relevant execution chain and traceback that occurs during these errors (where I replace the base directory using ~ although the system is on Windows hence the backslashes):

File "~\holoviews\util\", line 849, in render
    return renderer_obj.get_plot_state(obj)
  File "~\holoviews\plotting\", line 275, in get_plot_state
    obj = self_or_cls.get_plot(obj=obj, renderer=renderer, **kwargs)
  File "~\holoviews\plotting\bokeh\", line 74, in get_plot
    plot.document.theme = self_or_cls.theme
  File "~\bokeh\document\", line 225, in theme
    if self._theme is theme:
AttributeError: 'Document' object has no attribute '_theme'

Unfortunately I can’t begin to speculate without a complete Minimal Reproducible Example.

Otherwise you can see in the latest branch that self._theme is always unconditionally set in Document.__init__, so without an MRE all I can suggest is to try newer/different versions.

That said, I guess there are also classmethod factory constructors so maybe it’s possible there is a codepath going through those that does not supply a theme. That’s really a question of how Panel uses Bokeh, however (though perhaps Bokeh could warn or error or suply a default in case the input JSON is missing a theme). cc @Philipp_Rudiger @James_A_Bednar1