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

Notification initialisation is not properly working #6178

Closed
ruzzle opened this issue Jan 10, 2024 · 6 comments · Fixed by #6229
Closed

Notification initialisation is not properly working #6178

ruzzle opened this issue Jan 10, 2024 · 6 comments · Fixed by #6229
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@ruzzle
Copy link

ruzzle commented Jan 10, 2024

In Jupyter Lab (version 4.0.9), I tried to use panel notifications, like:

import panel as pn

pn.extension(notifications=True)
pn.state.notifications.error('test')

The strange thing was that on the first time, the notification did not appear, but every time afterwards, the notification did appear. I produced this issue using the official docker image (quay.io/jupyter/minimal-notebook) and installed panel (1.3.6) via pip.

I eventually found the issue by debugging cell execution twice. During the first execution of pn.extension() and the second execution I found a difference: It appeared that panel_extension._display_globals in panel.config is not called the first time but only the second time. I presume this should not be the case?

To verify, I added panel_extension._display_globals() manually after loading the extension, which resolved the issue

For completion, here is also some system context:

IPython          : 8.18.1
ipykernel        : 6.26.0
ipywidgets       : not installed
jupyter_client   : 8.6.0
jupyter_core     : 5.5.0
jupyter_server   : 2.12.1
jupyterlab       : 4.0.9
nbclient         : 0.8.0
nbconvert        : 7.12.0
nbformat         : 5.9.2
notebook         : 7.0.6
qtconsole        : not installed
traitlets        : 5.14.0
@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Jan 10, 2024
@philippjfr philippjfr added this to the v1.3.7 milestone Jan 10, 2024
@philippjfr
Copy link
Member

I can reproduce your issue but not what you reported about the cause, specifically _display_globals IS called the first time for me. For me it's not working because Notyf doesn't appear to be loaded correctly.

@philippjfr
Copy link
Member

Nevermind, the Notyf thing was due a local development version. I can't reproduce your issue at all unfortunately. Do you have an idea what causes _display_globals not to be called? The only thing I can think of is that you maybe have another extension call in the same cell, e.g. this reproduces the issue for me:

import panel as pn
import hvplot.pandas # Initializes the extension once

pn.extension(notifications=True)

@ruzzle
Copy link
Author

ruzzle commented Jan 10, 2024

With the following you should be able to reproduce it:

docker run --rm -t -i -p 8888:8888 quay.io/jupyter/minimal-notebook
docker exec -t -i <container_name> pip install panel

Then open up jupyter lab, create a new notebook, paste the code and execute

@ruzzle
Copy link
Author

ruzzle commented Jan 12, 2024

To add to your question, _display_globals is called within the __call__ function only if published is set to False, so I presume published is somehow set to True the first time.

Assuming that is the case, looking at the code in __call__, it may have something to do with the assignment of published, but cannot tell what it would be...

nb_loaded = published = getattr(self, '_repeat_execution_in_cell', False)

@philippjfr
Copy link
Member

The real issue seems to be that when the cell executes for the first time the Jupyter comm machinery does not seem to be fully set up, so while the NotificationArea component is rendered it is not correctly connected to the Comm, which means messages sent to it won't be registered. This is likely a general problem with all components rendered in the first cell. I'll keep investigating.

@philippjfr
Copy link
Member

I've figured out the issue. On first load BokehJS and Panel.JS aren't initialized yet and these take a while to load. However on the server side we don't know this so we instantiate the Comm that will be used to send data to the frontend. However if you attempt to initialize a Comm that hasn't yet been set up on the frontend it will never connect, so we end up in a scenario where even once everything is initialized any Comm that was set up before the frontend was fully initialized will not receive messages correctly. Will have to see if there's some way around this, but it's sadly not a simple problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants