DateTime fields in API cause 400 Bad request during end of daylight saving time 25/10 02:00:00-02:59:59 #4212

Closed
opened 2025-12-29 18:33:52 +01:00 by adam · 4 comments
Owner

Originally created by @beejaz on GitHub (Oct 26, 2020).

Environment

  • Python version: 2.7.12
  • NetBox version: 2.9.7 (also found in 2.9.4)

Steps to Reproduce

  1. Add a new site
curl -X POST "https://netbox/api/dcim/sites/" -H "accept: application/json" -H "Content-Type: application/json" -H "X-CSRFToken: token" -d "{ \"name\": \"Test Netbox Site\", \"slug\": \"test-netbox-site\"}"
  1. Search for sites (same problem on all date time fields) last updated with a DateTime in the range of 2020-10-25 02:00:00 and 2020-10-25 02:59:59
curl -X GET "https://netbox/api/dcim/sites/?last_updated__gte=2020-10-25%2002%3A00%3A00" -H "accept: application/json" -H "X-CSRFToken: token"
  1. Change datetime to 2020-10-25 03:00:00
curl -X GET "https://netbox/api/dcim/sites/?last_updated__gte=2020-10-25%2003%3A00%3A00" -H "accept: application/json" -H "X-CSRFToken: token"

Expected Behavior

A working response with status 200, it works

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 1941,
      "url": "https://netbox/api/dcim/sites/1941/",
      "name": "Test Netbox Site",
      "slug": "test-netbox-site",
      "status": {
        "value": "active",
        "label": "Active"
      },
      "region": null,
      "tenant": null,
      "facility": "",
      "asn": null,
      "time_zone": null,
      "description": "",
      "physical_address": "",
      "shipping_address": "",
      "latitude": null,
      "longitude": null,
      "contact_name": "",
      "contact_phone": "",
      "contact_email": "",
      "comments": "",
      "tags": [],
      "custom_fields": {
        "auto_ingested": false,
        "pop_owner": null,
        "pop_project": null,
        "pop_type": null,
        "sync_to_kundreg": false
      },
      "created": "2020-10-26",
      "last_updated": "2020-10-26T09:10:50.755578+01:00",
      "circuit_count": null,
      "device_count": null,
      "prefix_count": null,
      "rack_count": null,
      "virtualmachine_count": null,
      "vlan_count": null
    }
  ]
}

Observed Behavior

API breaks, gives error 400 Bad Request because it couldn't parse the date in CET timezone. Probably due to daylight saving time ending at 25/10 03:00:00

It breaks for all timestamps in the range between 02:00:00 and 02:59:59 on 2020-10-25 and this happens to all datetime fields eg. sites, devices, ipam etc. For example "Last updated, Last updated gte, Last updated lte" but not "created" because its only a Date.

Test server are in Sweden, UTC+1 with CET timezone

date
Mon Oct 26 09:34:44 CET 2020
{
  "last_updated__gte": [
    "2020-10-25 02:00:00 couldn’t be interpreted in time zone CET; it may be ambiguous or it may not exist."
  ]
}
Originally created by @beejaz on GitHub (Oct 26, 2020). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/g/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: 2.7.12 * NetBox version: 2.9.7 (also found in 2.9.4) <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. Add a new site ``` curl -X POST "https://netbox/api/dcim/sites/" -H "accept: application/json" -H "Content-Type: application/json" -H "X-CSRFToken: token" -d "{ \"name\": \"Test Netbox Site\", \"slug\": \"test-netbox-site\"}" ``` 2. Search for sites (same problem on all date time fields) last updated with a DateTime in the range of 2020-10-25 02:00:00 and 2020-10-25 02:59:59 ``` curl -X GET "https://netbox/api/dcim/sites/?last_updated__gte=2020-10-25%2002%3A00%3A00" -H "accept: application/json" -H "X-CSRFToken: token" ``` 3. Change datetime to 2020-10-25 03:00:00 ``` curl -X GET "https://netbox/api/dcim/sites/?last_updated__gte=2020-10-25%2003%3A00%3A00" -H "accept: application/json" -H "X-CSRFToken: token" ``` <!-- What did you expect to happen? --> ### Expected Behavior A working response with status 200, it works ``` { "count": 1, "next": null, "previous": null, "results": [ { "id": 1941, "url": "https://netbox/api/dcim/sites/1941/", "name": "Test Netbox Site", "slug": "test-netbox-site", "status": { "value": "active", "label": "Active" }, "region": null, "tenant": null, "facility": "", "asn": null, "time_zone": null, "description": "", "physical_address": "", "shipping_address": "", "latitude": null, "longitude": null, "contact_name": "", "contact_phone": "", "contact_email": "", "comments": "", "tags": [], "custom_fields": { "auto_ingested": false, "pop_owner": null, "pop_project": null, "pop_type": null, "sync_to_kundreg": false }, "created": "2020-10-26", "last_updated": "2020-10-26T09:10:50.755578+01:00", "circuit_count": null, "device_count": null, "prefix_count": null, "rack_count": null, "virtualmachine_count": null, "vlan_count": null } ] } ``` <!-- What happened instead? --> ### Observed Behavior API breaks, gives error 400 Bad Request because it couldn't parse the date in CET timezone. Probably due to daylight saving time ending at 25/10 03:00:00 It breaks for all timestamps in the range between 02:00:00 and 02:59:59 on 2020-10-25 and this happens to all datetime fields eg. sites, devices, ipam etc. For example "Last updated, Last updated gte, Last updated lte" but not "created" because its only a Date. Test server are in Sweden, UTC+1 with CET timezone ``` date Mon Oct 26 09:34:44 CET 2020 ``` ``` { "last_updated__gte": [ "2020-10-25 02:00:00 couldn’t be interpreted in time zone CET; it may be ambiguous or it may not exist." ] } ```
adam added the type: bugstatus: needs ownerpending closure labels 2025-12-29 18:33:52 +01:00
adam closed this issue 2025-12-29 18:33:53 +01:00
Author
Owner

@jeremystretch commented on GitHub (Oct 26, 2020):

I haven't looked into this, but it likely involves needing to make the timestamp timezone-aware before employing it in a queryset filter. Also:

Python version: 2.7.12

Please specify the correct Python version (NetBox does not run on Python 2.7).

@jeremystretch commented on GitHub (Oct 26, 2020): I haven't looked into this, but it likely involves needing to make the timestamp timezone-aware before employing it in a queryset filter. Also: > Python version: 2.7.12 Please specify the correct Python version (NetBox does not run on Python 2.7).
Author
Owner

@beejaz commented on GitHub (Nov 16, 2020):

Sorry about Python version, it was not 2.7 it is Python 3.7.7

@beejaz commented on GitHub (Nov 16, 2020): Sorry about Python version, it was not 2.7 it is Python 3.7.7
Author
Owner

@stale[bot] commented on GitHub (Jan 1, 2021):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@stale[bot] commented on GitHub (Jan 1, 2021): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@stale[bot] commented on GitHub (Jan 17, 2021):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@stale[bot] commented on GitHub (Jan 17, 2021): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4212