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 handling of Columns<> events #206

Merged
merged 1 commit into from
May 31, 2024

Conversation

maximlt
Copy link
Contributor

@maximlt maximlt commented May 31, 2024

Fixes holoviz/panel#5513

I've so far only been able to "test" this change for ColumnsPatched, not form ColumnsStreamed, but I'd be happy to also "test" it if someone can indicate how to trigger it.


This example used to fail when updating the table in a notebook. Note it wraps the model with BokehModel from jupyter_bokeh (as discussed in #199) to reproduce the issue with Bokeh code only, avoiding Panel.

from IPython.display import display
from jupyter_bokeh.widgets import BokehModel
from bokeh.io import output_notebook
from bokeh.models import ColumnDataSource, DataTable, TableColumn

output_notebook()

source = ColumnDataSource(dict(values=[0, 1, 2, 3, 4]))
columns = [TableColumn(field="values")]
data_table = DataTable(source=source, columns=columns, editable=True, height=150)

display(BokehModel(data_table))

The traceback that was raised in that case:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File /private/tmp/issue_key/.venv/lib/python3.12/site-packages/jupyter_bokeh/widgets.py:162, in BokehModel._sync_model(self, _model, content, _buffers)
    [160](https://file+.vscode-resource.vscode-cdn.net/private/tmp/issue_key/.venv/lib/python3.12/site-packages/jupyter_bokeh/widgets.py:160) elif kind == "ColumnsPatched":
    [161](https://file+.vscode-resource.vscode-cdn.net/private/tmp/issue_key/.venv/lib/python3.12/site-packages/jupyter_bokeh/widgets.py:161)     model = content["model"]
--> [162](https://file+.vscode-resource.vscode-cdn.net/private/tmp/issue_key/.venv/lib/python3.12/site-packages/jupyter_bokeh/widgets.py:162)     patches = content["data"]
    [164](https://file+.vscode-resource.vscode-cdn.net/private/tmp/issue_key/.venv/lib/python3.12/site-packages/jupyter_bokeh/widgets.py:164)     assert isinstance(model, ColumnDataSource)
    [165](https://file+.vscode-resource.vscode-cdn.net/private/tmp/issue_key/.venv/lib/python3.12/site-packages/jupyter_bokeh/widgets.py:165)     model.patch(patches, setter=setter)

KeyError: 'data'

With the changes applied, it seems to work well:

jupyter_bokeh2

@philippjfr
Copy link
Contributor

This is great, thank you! @mattpap Could you cut a release when you get a chance?

@philippjfr philippjfr merged commit 028343a into bokeh:main May 31, 2024
2 checks passed
@mattpap mattpap added this to the 4.0.5 milestone May 31, 2024
@mattpap
Copy link
Contributor

mattpap commented May 31, 2024

I will release later today.

@philippjfr
Copy link
Contributor

Thanks, appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyError 'data' on table edit
3 participants