holoviz/lumen

Select widget filter accepts a default value that is not part of the options

maximlt opened this issue · 2 comments

The following filter's spec, defined in the source spec, doesn't raise any error even if the default isn't part of the options (obtained from the schema).

    filters:
      species:
        type: widget
        field: species
        multi: false
        default: bad

Before any value is selected in the UI, the filter has a value='bad' and the widget has a correct value (i.e. one part of its options).

This is ultimately down to panel, where the Select widget doesn't raise any error if one tries to set a value not part of the options.

import panel as pn
from panel.widgets import Select
s = Select(value='b', options=['a', 'b'])
print(s.value)  # 'b'
s.value = 'c'
print(s.value)  # 'a'

Instead panel just sets the first the new value to the first option available (https://github.com/holoviz/panel/blob/master/panel/widgets/select.py#L73).

@philippjfr why does panel have this behavior? I'd expect an error to be raised (as with param.Selector) but maybe there's a good reason for not following param here.

Yeah, this is a Panel issue. The Select widget shouldn't allow this.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.