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

TimeZoneSerializerField does not handle the empty string case #86

Closed
sangiovannidev opened this issue Apr 1, 2022 · 2 comments
Closed

Comments

@sangiovannidev
Copy link

sangiovannidev commented Apr 1, 2022

Hi, thanks for your hard work on django-timezone-field!

TimeZoneSerializerField.to_internal_value() seems not to fully handle the empty string ("") case.
With use_pytz=False, when the empty string is fed to the the method, it is passed to ZoneInfo(), which raises a ValueError, as follows:

>>> from zoneinfo import ZoneInfo
>>> ZoneInfo('')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/zoneinfo/_tzpath.py", line 67, in find_tzfile
    _validate_tzfile_path(key)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/zoneinfo/_tzpath.py", line 91, in _validate_tzfile_path
    raise ValueError(
ValueError: ZoneInfo keys must be normalized relative paths, got:

I would expect to_internal_value() to raise a ValidationError instead, which could be handled appropriately by DRF's exception handling machinery.

Please let me know if I can be of further help.

Thanks!

@mfogel mfogel closed this as completed in 7c1b537 Jun 18, 2023
@ejain
Copy link

ejain commented Jun 25, 2024

Shouldn't empty strings be allowed if the field has required=False and allow_null=True?

@mfogel
Copy link
Owner

mfogel commented Jul 7, 2024

@ejain after #137 is merged, empty strings will be allowed if allow_blank=True is specified as documented by DJRF for their CharField

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

No branches or pull requests

3 participants