I’ve encountered an issue after upgrading my app from Panel 1.3.8 to Panel 1.6.3.
Everything worked fine with version 1.3.8, but after upgrading to 1.6.3, I started getting the following error under specific circumstances:
RuntimeError: Models must be owned by only a single document, ImportedStyleSheet(id='p1108', ...) is already in a doc
This happens when I follow these steps in my app:
- Navigate to the Article page.
- Click the “Start local session” button (this dynamically updates part of the layout).
- Navigate to the Settings page.
- Return to the Article page.
- Click the “Start local session” button again.
At this point, the error is triggered. The same code and workflow worked without issues in Panel 1.3.8.
From the error message, it seems to be related to the ImportedStyleSheet
being added to the Bokeh document multiple times. My guess is that some components (maybe a template or a dynamically created view) are being reused or not properly cleaned up when switching pages.
I’ve created a minimal reproducible example that demonstrates the issue and would be happy to share it if helpful.
Could you help me understand what changed in recent versions that might be causing this? And what is the recommended way to avoid or handle this error?
Thank you in advance for your time and support!
Full traceback
Exception in callback functools.partial(<bound method IOLoop._discard_future_result of <tornado.platform.asyncio.AsyncIOMainLoop object at 0x105d0b700>>, <Task finished name='Task-304' coro=<ServerSession.with_document_locked() done, defined at /Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/bokeh/server/session.py:77> exception=RuntimeError("Models must be owned by only a single document, ImportedStyleSheet(id='p1094', ...) is already in a doc")>)
Traceback (most recent call last):
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/tornado/ioloop.py", line 750, in _run_callback
ret = callback()
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/tornado/ioloop.py", line 774, in _discard_future_result
future.result()
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/bokeh/server/session.py", line 94, in _needs_document_lock_wrapper
result = func(self, *args, **kwargs)
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/bokeh/server/session.py", line 226, in with_document_locked
return func(*args, **kwargs)
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/bokeh/document/callbacks.py", line 495, in wrapper
return invoke_with_curdoc(doc, invoke)
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/bokeh/document/callbacks.py", line 453, in invoke_with_curdoc
return f()
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/bokeh/document/callbacks.py", line 494, in invoke
return f(*args, **kwargs)
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/bokeh/document/callbacks.py", line 184, in remove_then_invoke
return callback()
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/panel/reactive.py", line 326, in _scheduled_update_model
self._update_model(events, msg, root, model, doc, comm)
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/panel/layout/base.py", line 257, in _update_model
with freeze_doc(doc, model, msg, force=update_children):
File "/opt/homebrew/Cellar/python@3.10/3.10.17/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 142, in __exit__
next(self.gen)
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/panel/io/document.py", line 624, in freeze_doc
doc.models._pop_freeze()
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/bokeh/document/models.py", line 288, in _pop_freeze
self.recompute()
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/bokeh/document/models.py", line 235, in recompute
ma._attach_document(document)
File "/Users/ivannaparfeniuk/.local/share/virtualenvs/panel_example-ClUGGO8J/lib/python3.10/site-packages/bokeh/model/model.py", line 596, in _attach_document
raise RuntimeError(f"Models must be owned by only a single document, {self!r} is already in a doc")
RuntimeError: Models must be owned by only a single document, ImportedStyleSheet(id='p1094', ...) is already in a doc