# Buggy code
def __init__(self, root_model, link, source, target=None, arg_overrides={}):
    self.root_model = root_model
    self.link = link
    self.source = source
    self.target = target
    self.arg_overrides = arg_overrides
    self.validate()
    specs = self._get_specs(link, source, target)
    for src_spec, tgt_spec, code in specs:
        self._init_callback(root_model, link, source, src_spec, target, tgt_spec, code)


# Traceback (KeyError)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/PythonWorkspace/py37/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
968
969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
971             return None
972         else:

~/PythonWorkspace/modules/panel/panel/template.py in _repr_mimebundle_(self, include, exclude)
156         doc = _Document()
157         comm = state._comm_manager.get_server_comm()
--> 158         self._init_doc(doc, comm, notebook=True)
159         return render_template(doc, comm)
160

~/PythonWorkspace/modules/panel/panel/template.py in _init_doc(self, doc, comm, title, notebook)
113         ref = preprocess_root.ref['id']
114         for name, (obj, tags) in self._render_items.items():
--> 115             model = obj.get_root(doc, comm)
116             doc.on_session_destroyed(obj._server_destroy)
117             for sub in obj.select(Viewable):

~/PythonWorkspace/modules/panel/panel/viewable.py in get_root(self, doc, comm)
527         doc = doc or _curdoc()
528         root = self._get_model(doc, comm=comm)
--> 529         self._preprocess(root)
530         ref = root.ref['id']
531         state._views[ref] = (self, root, doc, comm)

~/PythonWorkspace/modules/panel/panel/viewable.py in _preprocess(self, root)
348         """
349         for hook in self._preprocessing_hooks:
--> 350             hook(self, root)
351
352     def _render_model(self, doc=None, comm=None):

~/PythonWorkspace/modules/panel/panel/links.py in _process_callbacks(cls, root_view, root_model)
126             overrides = arg_overrides.get(id(link), {})
127             callbacks.append(cb(root_model, link, src, tgt,
--> 128                                 arg_overrides=overrides))
129         return callbacks
130

~/PythonWorkspace/modules/panel/panel/links.py in __init__(self, root_model, link, source, target, arg_overrides)
205         specs = self._get_specs(link, source, target)
206         for src_spec, tgt_spec, code in specs:
--> 207             self._init_callback(root_model, link, source, src_spec, target, tgt_spec, code)
208
209     @classmethod

~/PythonWorkspace/modules/panel/panel/links.py in _init_callback(self, root_model, link, source, src_spec, target, tgt_spec, code)
270
271         for k, v in dict(link.args, **self.arg_overrides).items():
--> 272             arg_model = self._resolve_model(root_model, v, None)
273             if arg_model is not None:
274                 references[k] = arg_model

~/PythonWorkspace/modules/panel/panel/links.py in _resolve_model(cls, root_model, obj, model_spec)
243                 model = obj.handles[handle_spec]
244         elif isinstance(obj, Viewable):
--> 245             model, _ = obj._models[root_model.ref['id']]
246         elif isinstance(obj, BkModel):
247             model = obj

KeyError: '1046'

# Fixed code
def __init__(self, root_model, link, source, target=None, arg_overrides={}):
    self.root_model = root_model
    self.link = link
    self.source = source
    self.target = target
    self.arg_overrides = arg_overrides
    self.validate()
    specs = self._get_specs(link, source, target)
    for src_spec, tgt_spec, code in specs:
        try:
            self._init_callback(
                root_model, link, source, src_spec, target, tgt_spec, code
            )
        except Exception:
            pass