netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
16.07k stars 2.58k forks source link

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

Closed beejaz closed 3 years ago

beejaz commented 4 years ago

Environment

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"

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."
  ]
}
jeremystretch commented 4 years ago

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

beejaz commented 3 years ago

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

stale[bot] commented 3 years ago

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 3 years ago

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.