ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

AttributeError raised by DatetimePicker

Open huyuhuster opened this issue 3 years ago • 2 comments

https://github.com/jupyter-widgets/ipywidgets/blob/84abba08bd242133b63fe992ebc65b8358b8b2f9/python/ipywidgets/ipywidgets/widgets/widget_datetime.py#L56

This line will raise an error AttributeError when I clear the picked datetime. As described in: https://github.com/vidartf/ipydatetime/issues/8

venv/lib/python3.8/site-packages/ipydatetime/datetime_widget.py in _validate_tz(self, value)
    135 
    136     def _validate_tz(self, value):
--> 137         if value.tzinfo is not None:
    138             raise TraitError('%s values needs to be timezone unaware' % (self.__class__.__name__,))
    139         return value

AttributeError: 'NoneType' object has no attribute 'tzinfo'

huyuhuster avatar Jun 23 '22 08:06 huyuhuster

@huyuhuster The issue you linked describes a proposed solution. Do you have the opportunity to verify if that works? And if it does, would you be interested in making a PR with it? :)

vidartf avatar Jun 23 '22 08:06 vidartf

@huyuhuster The issue you linked describes a proposed solution. Do you have the opportunity to verify if that works? And if it does, would you be interested in making a PR with it? :)

@vidartf I will try that later. If it work, I will make a PR with it.

huyuhuster avatar Jun 24 '22 00:06 huyuhuster

@huyuhuster Actually, I'm not able to reproduce this, and we do have a unit test that covers this case:

https://github.com/jupyter-widgets/ipywidgets/blob/90e6be0212faefcf6643c9aa0ec0a7429a01d083/python/ipywidgets/ipywidgets/widgets/tests/test_widget_datetime.py#L28-L34

I've tested this with the version of Python indicated by the error report (py 3.8), and it doesn't seem to trigger for me. I've tried some older versions of traitlets as well, but I'm simply not able to reproduce it. Would you mind sharing which versions of python (CPython?), traitlets, and ipywidgets you are using?

vidartf avatar Sep 01 '22 12:09 vidartf

Ah, I see why the test didn't check it: the trait's _validate shortcuts for None if allow_none is true, but when being set from the client side with hold_traits_notification, this shortcut does not happen.

vidartf avatar Sep 01 '22 14:09 vidartf