ObjectSelector does not reset to None if objects are empty
- Dominant language
- Python
- Stars
- 521
- Forks
- 86
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 35
Description
#### My Pain
I'm trying to create an app where the objects of an ObjectSelector updates dynamically.
For example if you have Region and Country ObjectSelectors you would like the objects of the Country ObjectSelector to change when the value of the Region ObjectSelector change.
But sometimes the objects of the ObjectSelector might be the empty dictionary or list. This is not handled well.
The value is not automatically changed to None and it cannot be done programmatically. Instead the old value which is no longer in the list is kept.
I would expect the value to be set to None. Because otherwise if would have to check the objects before I running some function based on the change. Thats not natural I believe.
```bash
$ python 'issue_object_selector.py'
1
Traceback (most recent call last):
File "issue_object_selector.py", line 20, in
app.value=None
File "C:\Users\masma\source\repos\orsteddcsmarketsanalytics\api\.venv\lib\site-packages\param\parameterized.py", line 294, in _f
instance_param.__set__(obj, val)
File "C:\Users\masma\source\repos\orsteddcsmarketsanalytics\api\.venv\lib\site-packages\param\parameterized.py", line 296, in _f
return f(self, obj, val)
File "C:\Users\masma\source\repos\orsteddcsmarketsanalytics\api\.venv\lib\site-packages\param\parameterized.py", line 823, in __set__
self._validate(val)
File "C:\Users\masma\source\repos\orsteddcsmarketsanalytics\api\.venv\lib\site-packages\param\__init__.py", line 1242, in _validate
"valid options include %s"%(val,attrib_name, items))
ValueError: None not in Parameter value's list of possible objects, valid options include []
(.venv)
```
```python
import param
OBJECTS_ALL = {"First":1, "Second": 2}
class App(param.Parameterized):
value = param.ObjectSelector(default=1, objects=OBJECTS_ALL)
@param.depends("value", watch=True)
def update(self):
print(self.param.value.objects)
print(self.value)
app = App()
object_dict = {}
objects = list(object_dict.values())
app.param.names = object_dict
app.param.value.objects = objects
assert app.value==1
print(app.value)
app.value=None
```
Contributor guide
Assessment
This issue has not been assessed yet.