You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Debugger widget inside template suppresses errors, breaks binding, and after reload show 'AttributeError: 'NoneType' object has no attribute 'document' 500 Server Error
#7436
Description of expected behavior and the observed behavior
I tried to add Debugger widget to a template-based Panel application (with widgets in the sidebar, and panels in the main pane).
I have created a simple application, with a widget, two bound function (one using the widget, one using the other bound function), and a simple Markdown pane. Each of the functions writes to logs using logger.debug on entry. The idea was to compare using pn.bind with pn.rx.
When I used the Debugger widget as shown in the documentation, that is simply in the cell, everything works correctly.
changing the selected in the Select widget changes the Markdown pane output
debug information appears in the Debugging widget, in the appropriate cell output
When I added MaterialTemplate with widget in sidebar, and Markdown widget in the main pane, and made that template .servable();, and then previewed with 'Preview with Panel' (and with panel serve), everything still worked correctly.
However, when I added the Debugger to the main pane, the application stopped working correctly. It either did not update the Markdown pane (bound functions do not work), or produced 500 Server Error.
In the first case, in the 'Serve with Panel':
changing the selected value didn't change the output
nothing appeared in the Debugger widget
In the second case I got the following strange error:
AttributeError: 'NoneType' object has no attribute 'document'
Often reloading the incorrectly working (but displayed) page lead to showing the error above. Further reloading have always shown the error.
Complete, minimal, self-contained example code that reproduces the issue
# notebooks/panel/00-panel-Debugger-demo.ipynbimportloggingimportpanelaspn#pn.extension('terminal', console_output='disable')pn.extension('terminal')
# testing the Debugger widgetdebug=pn.widgets.Debugger(
name='Debugger (level=DEBUG)',
only_last=False,
level=logging.DEBUG, logger_names=['panel.Debugger'])
debuglogger.debug("DEBUG")
logger.info("INFO")
logger.warning("WARNING")
logger.error("ERROR")
widget=pn.widgets.Select(name='Select', options=['Biology', 'Chemistry', 'Physics'])
defmarkdown_contents(value):
logger.debug(f"markdown_contents({value=})")
returnf"""Value is _{value}_"""defappend_exclamation(value: str) ->str:
logger.debug(f"append_exclamation({value=})")
returnvalue+"!!!"bound_markdown_contents=pn.bind(
markdown_contents, widget,
)
bound_append_exclamation=pn.bind(
append_exclamation, bound_markdown_contents,
)
# testing that bounding works correctly - it doespn.Column(widget, pn.pane.Str(bound_append_exclamation))
template=pn.template.MaterialTemplate(
site="debugger",
title="Debugger demo",
sidebar_width=300,
sidebar=[
widget,
],
main=[
pn.pane.Markdown(bound_append_exclamation),
pn.pane.Str(bound_append_exclamation),
],
)
template.main.extend([
# NOTE: with the line below commented out, everything works just finedebug,
])
template.servable(); # The ; is needed in the notebook to not display the template. Its not needed in a script
AttributeError: 'NoneType' object has no attribute 'document'
Traceback (most recent call last):
File "~/.venv/lib/python3.12/site-packages/panel/io/handlers.py", line 405, in run
exec(self._code, module.__dict__)
File "~/notebooks/panel/00-panel-Debugger-demo.ipynb", line 30, in <module>
"metadata": {},
File "/usr/lib/python3.12/logging/__init__.py", line 1527, in debug
self._log(DEBUG, msg, args, **kwargs)
File "/usr/lib/python3.12/logging/__init__.py", line 1684, in _log
self.handle(record)
File "/usr/lib/python3.12/logging/__init__.py", line 1700, in handle
self.callHandlers(record)
File "/usr/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
hdlr.handle(record)
File "/usr/lib/python3.12/logging/__init__.py", line 1022, in handle
rv = self.filter(record)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/logging/__init__.py", line 858, in filter
result = f.filter(record)
^^^^^^^^^^^^^^^^
File "~/.venv/lib/python3.12/site-packages/panel/widgets/debugger.py", line 97, in filter
widget_session_ids = set(m.document.session_context.id
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/.venv/lib/python3.12/site-packages/panel/widgets/debugger.py", line 99, in <genexpr>
tuple()) if m.document.session_context)
^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'document'
I may be interested in making a pull request to address this
The text was updated successfully, but these errors were encountered:
This looks like re-broken issue #5235 (supposedly fixed in v1.4.0, but present in v1.5.2). The same work-around of wrapping Debugger in some layout, like pn.Row or pn.Card works.
ALL software version info
Software Version Info
Description of expected behavior and the observed behavior
I tried to add Debugger widget to a template-based Panel application (with widgets in the sidebar, and panels in the main pane).
I have created a simple application, with a widget, two bound function (one using the widget, one using the other bound function), and a simple Markdown pane. Each of the functions writes to logs using
logger.debug
on entry. The idea was to compare usingpn.bind
withpn.rx
.When I used the Debugger widget as shown in the documentation, that is simply in the cell, everything works correctly.
When I added MaterialTemplate with widget in sidebar, and Markdown widget in the main pane, and made that template
.servable();
, and then previewed with 'Preview with Panel' (and withpanel serve
), everything still worked correctly.However, when I added the Debugger to the main pane, the application stopped working correctly. It either did not update the Markdown pane (bound functions do not work), or produced 500 Server Error.
In the first case, in the 'Serve with Panel':
In the second case I got the following strange error:
Often reloading the incorrectly working (but displayed) page lead to showing the error above. Further reloading have always shown the error.
Complete, minimal, self-contained example code that reproduces the issue
Stack traceback and/or browser JavaScript console output
Stack traceback after reloading
The text was updated successfully, but these errors were encountered: