KeyError: 'id' - maybe issue?

Hi,

I ran into the following problem. I have this simple example:

from bokeh.models import GraphRenderer, StaticLayoutProvider
from bokeh.plotting import figure, curdoc

D = 10
gr = GraphRenderer()
gr.node_renderer.glyph.size = 10
ds = gr.node_renderer.data_source
ds.data = dict(index=[i for i in range(D * D)])

layout = {idx: (idx % D, idx // D) for idx in ds.data['index']}

gr.layout_provider = StaticLayoutProvider(graph_layout=layout)


plot = figure(x_range=(-1, D), y_range=(-1, D))
plot.renderers.append(gr)
curdoc().add_root(plot)

Graph rendering works, but there is following error:

2020-09-17 12:55:40,967 error handling message
 message: Message 'PATCH-DOC' content: {'events': [{'kind': 'ModelChanged', 'model': {'id': '1002'}, 'attr': 'y', 'new': {'expr': {}}}], 'references': []} 
 error: KeyError('id')
Traceback (most recent call last):
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/server/protocol_handler.py", line 90, in handle
    work = await handler(message, connection)
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/server/session.py", line 67, in _needs_document_lock_wrapper
    result = func(self, *args, **kwargs)
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/server/session.py", line 261, in _handle_patch
    message.apply_to_document(self.document, self)
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/protocol/messages/patch_doc.py", line 100, in apply_to_document
    doc._with_self_as_curdoc(lambda: doc.apply_json_patch(self.content, setter))
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/document/document.py", line 1169, in _with_self_as_curdoc
    return f()
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/protocol/messages/patch_doc.py", line 100, in <lambda>
    doc._with_self_as_curdoc(lambda: doc.apply_json_patch(self.content, setter))
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/document/document.py", line 410, in apply_json_patch
    patched_obj.set_from_json(attr, value, models=references, setter=setter)
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/core/has_props.py", line 345, in set_from_json
    descriptor.set_from_json(self, json, models, setter)
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/core/property/descriptors.py", line 1033, in set_from_json
    super().set_from_json(obj, json, models, setter)
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/core/property/descriptors.py", line 611, in set_from_json
    self.property.from_json(json, models),
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/core/property/either.py", line 90, in from_json
    return tp.from_json(json, models)
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/core/property/container.py", line 174, in from_json
    return { self.keys_type.from_json(key, models): self.values_type.from_json(value, models) for key, value in json.items() }
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/core/property/container.py", line 174, in <dictcomp>
    return { self.keys_type.from_json(key, models): self.values_type.from_json(value, models) for key, value in json.items() }
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/core/property/either.py", line 90, in from_json
    return tp.from_json(json, models)
  File "/home/katterrina/matfyz/rocnikac/venv/lib/python3.8/site-packages/bokeh/core/property/instance.py", line 87, in from_json
    model = models.get(json["id"])
KeyError: 'id'

Bokeh 2.2.1
Python 3.8
Ubuntu 20.04

Do you know what is the problem?

Thanks,
Katerina

Seems like a bug indeed. Could you please create a GitHub issue?

1 Like

GitHub issue: https://github.com/bokeh/bokeh/issues/10503

2 Likes