Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError raised by DatetimePicker #3500

Closed
huyuhuster opened this issue Jun 23, 2022 · 4 comments · Fixed by #3581
Closed

AttributeError raised by DatetimePicker #3500

huyuhuster opened this issue Jun 23, 2022 · 4 comments · Fixed by #3581

Comments

@huyuhuster
Copy link

This line will raise an error AttributeError when I clear the picked datetime. As described in:
vidartf/ipydatetime#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'
@vidartf
Copy link
Member

vidartf commented Jun 23, 2022

@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? :)

@huyuhuster
Copy link
Author

@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.

@vidartf
Copy link
Member

vidartf commented Sep 1, 2022

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

def test_time_validate_value_none():
t = datetime.datetime(2002, 2, 20, 13, 37, 42, 7, tzinfo=pytz.utc)
t_min = datetime.datetime(1442, 1, 1, tzinfo=pytz.utc)
t_max = datetime.datetime(2056, 1, 1, tzinfo=pytz.utc)
w = DatetimePicker(value=t, min=t_min, max=t_max)
w.value = None
assert w.value is None

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
Copy link
Member

vidartf commented Sep 1, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants