Description
NetBox version
v3.5.4
Python version
3.10
Steps to Reproduce
- make sure timezone is set to UTC
- create a custom field of type date_time (let's say "my_dt")
- set a value using the nebtox UI
- get the value with the REST API (will be in format "YYYY-mm-ddTHH:MM:SSZ")
- POST a new value using the same format (with the trailing Z) or modify any other custom_field of the object → netbox does not validate the format of my_dt
Expected Behavior
The input format of datetime should be compatible with the output format.
Observed Behavior
We receive this error:
Invalid value for custom field 'start_prep': Date and time values must be in ISO 8601 format (YYYY-MM-DD HH:MM:SS).
Correct me if I'm wrong, but the values observed through the API are serialized with django rest_framework, which could explain why there's a different format between the rest api and inside the database. But when we do a post, the validation go through extras/models/customfields.py and use datetime.fromisoformat()
(also for deserialisation).
Starting python 3.11 fromisoformat() is compatible with the YYYY-mm-ddTHH:MM:SSZ format, but not former version (see changed in version 3.11 in the doc). But it's not always easy to upgrade python.
I patched my version with dateutil.parser.parse()
instead of datetime.fromisoformat()
and it's working as expected. Should I make a PR?
Thanks