holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.63k stars 505 forks source link

Type Error when field deleted for DateRangePicker and other datetime widgets #7198

Closed eason9 closed 6 days ago

eason9 commented 2 weeks ago

ALL software version info

Panel - 1.4.5 Python - 3.9.19

Description of expected behavior and the observed behavior

Many of the datetime widgets produce an error when the input value is deleted.

Complete, minimal, self-contained example code that reproduces the issue

# Run this code, select a date range, and then delete the values with the "delete" or "backspace" key.

import panel as pn

pn.extension()

DRP_widget = pn.widgets.DateRangePicker()
pn.Column(DRP_widget, height=350)

Stack traceback and/or browser JavaScript console output

Here's an example error from pn.widgets.DateRangePicker:

ine 443, in _process_param_change msg['value'] = tuple(self._convert_date_to_string(v) for v in msg['value']) TypeError: 'NoneType' object is not iterable

Solution

It looks like there was an oversight regarding the possible input parameter values. Pretty easy to fix this, and I just wanted to mention it / idk how to add a PR. For example DateRangePicker can be fixed with:

import panel as pn

pn.extension()

class DateRangePicker_v2(pn.widgets.DateRangePicker):

    def __init__(self, **params):
        super().__init__(**params)

    def _process_param_change(self, msg):
        msg = super(pn.widgets.DateRangePicker, self)._process_param_change(msg)
        if ('value' in msg) and (msg['value'] != None):
            msg['value'] = tuple(self._convert_date_to_string(v) for v in msg['value'])
        if 'min_date' in msg:
            msg['min_date'] = self._convert_date_to_string(msg['min_date'])
        if 'max_date' in msg:
            msg['max_date'] = self._convert_date_to_string(msg['max_date'])
        return msg

DRP_v2_widget = DateRangePicker_v2()
pn.Column(DRP_v2_widget, height=350)
hoxbro commented 2 weeks ago

To create a PR, you can clone the repo, update the line, or edit it directly on Github. Some help is provided here: https://holoviz-dev.github.io/panel/developer_guide/index.html

This is, of course, only if you want to make a PR.