Skip to content

Commit 562a574

Browse files
authored
Merge pull request #3423 from R3myG/fix-jupyter-deprecation-warning
Fix DeprecationWarning in Jupyter integration (fixes #3416)
2 parents ef6bcf6 + f0165d3 commit 562a574

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1313
- [#3395](https://github.com/plotly/dash/pull/3395) Fix Components added through set_props() cannot trigger related callback functions. Fix [#3316](https://github.com/plotly/dash/issues/3316)
1414
- [#3397](https://github.com/plotly/dash/pull/3397) Add optional callbacks, suppressing callback warning for missing component ids for a single callback.
1515
- [#3415](https://github.com/plotly/dash/pull/3415) Fix the error triggered when only a single no_update is returned for client-side callback functions with multiple Outputs. Fix [#3366](https://github.com/plotly/dash/issues/3366)
16+
- [#3416](https://github.com/plotly/dash/issues/3416) Fix DeprecationWarning in dash/_jupyter.py by migrating from deprecated ipykernel.comm.Comm to comm module
1617

1718
## [3.2.0] - 2025-07-31
1819

dash/_jupyter.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
from IPython.core.display import HTML
2323
from IPython.core.ultratb import FormattedTB
2424
from retrying import retry
25-
from ipykernel.comm import Comm
25+
from comm import create_comm
2626
import nest_asyncio
2727

2828
import requests
2929

30-
_dash_comm = Comm(target_name="dash")
30+
_dash_comm = create_comm(target_name="dash")
3131
_dep_installed = True
3232
except ImportError:
3333
_dep_installed = False
@@ -97,10 +97,14 @@ def convert(name, locals=locals, formatarg=formatarg, formatvalue=formatvalue):
9797
def _send_jupyter_config_comm_request():
9898
# If running in an ipython kernel,
9999
# request that the front end extension send us the notebook server base URL
100-
if get_ipython() is not None:
101-
if _dash_comm.kernel is not None:
102-
_caller["parent"] = _dash_comm.kernel.get_parent()
103-
_dash_comm.send({"type": "base_url_request"})
100+
ipython = get_ipython()
101+
if (
102+
ipython is not None
103+
and hasattr(ipython, "kernel")
104+
and ipython.kernel is not None
105+
):
106+
_caller["parent"] = ipython.kernel.get_parent()
107+
_dash_comm.send({"type": "base_url_request"})
104108

105109

106110
def _jupyter_comm_response_received():
@@ -109,7 +113,8 @@ def _jupyter_comm_response_received():
109113

110114
def _request_jupyter_config(timeout=2):
111115
# Heavily inspired by implementation of CaptureExecution in the
112-
if _dash_comm.kernel is None:
116+
ipython = get_ipython()
117+
if ipython is None or not hasattr(ipython, "kernel") or ipython.kernel is None:
113118
# Not in jupyter setting
114119
return
115120

@@ -215,8 +220,15 @@ def __init__(self):
215220
@_dash_comm.on_msg
216221
def _receive_message(msg):
217222
prev_parent = _caller.get("parent")
218-
if prev_parent and prev_parent != _dash_comm.kernel.get_parent():
219-
_dash_comm.kernel.set_parent(
223+
ipython = get_ipython()
224+
if (
225+
prev_parent
226+
and ipython is not None
227+
and hasattr(ipython, "kernel")
228+
and ipython.kernel is not None
229+
and prev_parent != ipython.kernel.get_parent()
230+
):
231+
ipython.kernel.set_parent(
220232
[prev_parent["header"]["session"]], prev_parent
221233
)
222234
del _caller["parent"]

0 commit comments

Comments
 (0)