How to change alert properties after creation

Hi @nritsche

Could you try and see if Alert._rename = {**Markdown._rename, "alert_type": None} could solve the issue. (It’s a hack). It needs to be done before you instantiate my_alert.

This is a bug. Please help by filing on Github.


Thanks @marc!
Your suggestion works. I’m going to create an issue. Btw, if I change .text nothing happens. I have to change .object. I guess that’s a similar issue?

btw, you edited my post when you probably wanted to reply.

1 Like

Thanks @nritsche. I’ve inserted the original post below

After creating an alert with

my_alert = pn.pane.Alert("foo", alert_type="primary")

I want to change it’s properties later. I tried

my_alert.alert_type = "success"
my_alert.object = "foo!"

, which works, but gives me a

  File "/home/rick/bondia/bondia/", line 209, in _click_opinion
    my_alert.alert_type = "success"
  File "/home/rick/.local/lib/python3.8/site-packages/param/", line 302, in _f
    instance_param.__set__(obj, val)
  File "/home/rick/.local/lib/python3.8/site-packages/param/", line 304, in _f
    return f(self, obj, val)
  File "/home/rick/.local/lib/python3.8/site-packages/param/", line 915, in __set__
    obj.param._call_watcher(watcher, event)
  File "/home/rick/.local/lib/python3.8/site-packages/param/", line 1554, in _call_watcher
  File "/home/rick/.local/lib/python3.8/site-packages/panel/", line 175, in _param_change
    self._update_model(events, msg, root, model, doc, comm)
  File "/home/rick/.local/lib/python3.8/site-packages/panel/", line 132, in _update_model
    self._changing[root.ref['id']] = [
  File "/home/rick/.local/lib/python3.8/site-packages/panel/", line 134, in <listcomp>
    if not model.lookup(attr).property.matches(getattr(model, attr), value)
  File "/home/rick/.local/lib/python3.8/site-packages/bokeh/core/", line 417, in lookup
    return getattr(cls, name)
AttributeError: type object 'HTML' has no attribute 'alert_type'

So I got a working solution with

    my_alert.alert_type = "success"
except AttributeError:
my_alert.object = "foo!"

Is there a better way?

@nritsche. The workaround should be extended to

Alert._rename=dict(Markdown._rename, alert_type=None)

And please note the documentation is wrong. You should not use text but object to change the text.

I’ve created a bug report and PR with a fix