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

Fix compatibility with bokeh 2.4 DocumentCallbackManager #2687

Merged
merged 2 commits into from
Aug 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions panel/io/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from bokeh.models import Box, ColumnDataSource, Model
from bokeh.protocol import Protocol

from ..util import bokeh_version
from .state import state

#---------------------------------------------------------------------
Expand All @@ -20,6 +21,11 @@ def diff(doc, binary=True, events=None):
Returns a json diff required to update an existing plot with
the latest plot data.
"""
if events is None:
if bokeh_version >= '2.4':
events = list(doc.callbacks._held_events)
else:
events = list(doc._held_events)
events = list(doc._held_events) if events is None else events
if not events or state._hold:
return None
Expand Down Expand Up @@ -54,12 +60,19 @@ def add_to_doc(obj, doc, hold=False):
# Add new root
remove_root(obj)
doc.add_root(obj)
if doc._hold is None and hold:
if bokeh_version >= '2.4':
doc_hold = doc.callbacks.hold_value
else:
doc_hold = doc._hold
if doc_hold is None and hold:
doc.hold()

@contextmanager
def hold(doc, policy='combine', comm=None):
held = doc._hold
if bokeh_version >= '2.4':
held = doc.callbacks.hold_value
else:
held = doc._hold
try:
if policy is None:
doc.unhold()
Expand All @@ -68,7 +81,10 @@ def hold(doc, policy='combine', comm=None):
yield
finally:
if held:
doc._hold = held
if bokeh_version >= '2.4':
doc.callbacks._hold = held
else:
doc._hold = held
else:
if comm is not None:
from .notebook import push
Expand Down
5 changes: 4 additions & 1 deletion panel/io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,10 @@ def unlocked():
return
connections = curdoc.session_context.session._subscribed_connections

hold = curdoc._hold
if bokeh_version >= '2.4':
hold = curdoc.callbacks.hold_value
else:
hold = curdoc._hold
if hold:
old_events = list(curdoc._held_events)
else:
Expand Down
7 changes: 5 additions & 2 deletions panel/pane/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ..io import remove_root
from ..io.notebook import push
from ..util import escape
from ..util import escape, bokeh_version
from ..viewable import Layoutable
from .base import PaneBase
from .ipywidget import IPyWidget
Expand All @@ -32,7 +32,10 @@ def _wrap_callback(cb, wrapped, doc, comm, callbacks):
replaces the wrapped callback with the real one while the callback
is exectuted to ensure the callback can be removed as usual.
"""
hold = doc._hold
if bokeh_version >= '2.4':
hold = doc.callbacks.hold_value
else:
hold = doc._hold
doc.hold('combine')
if wrapped in callbacks:
index = callbacks.index(wrapped)
Expand Down
2 changes: 1 addition & 1 deletion panel/reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ def _set_on_model(self, msg, root, model):
model.update(**msg)
finally:
if old:
self._chaning[root.ref['id']] = old
self._changing[root.ref['id']] = old
else:
del self._changing[root.ref['id']]

Expand Down
7 changes: 5 additions & 2 deletions panel/viewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .io.save import save
from .io.state import state
from .io.server import init_doc, serve
from .util import escape, param_reprs
from .util import bokeh_version, escape, param_reprs


class Layoutable(param.Parameterized):
Expand Down Expand Up @@ -266,7 +266,10 @@ def _on_msg(self, ref, manager, msg):
"""
root, doc, comm = state._views[ref][1:]
patch_cds_msg(root, msg)
held = doc._hold
if bokeh_version >= '2.4':
held = doc.callbacks.hold_value
else:
held = doc._hold
patch = manager.assemble(msg)
doc.hold()
patch.apply_to_document(doc, comm.id)
Expand Down