API returns last_updated Field with Inconsistent Timezones #2016

Closed
opened 2025-12-29 17:21:30 +01:00 by adam · 1 comment
Owner

Originally created by @ghost on GitHub (Sep 19, 2018).

Environment

  • Python version: 3.4.9
  • NetBox version: 2.4.4

Steps to Reproduce

To reproduce, set a non-UTC timezone and compare the outputs of
GET /extras/object-changes/?limit=100000
GET /circuits/circuits/

The "last_updated" JSON field returned by the /extras/object-changes/ and /circuits/circuits/ API calls use different timezones when representing the same bit of data. The times shown are correct, but are displayed inconsistently.

We use BST (UTC+1), so normally timezones appear as +01:00 at this point in the year.
configuration.py has TIME_ZONE = 'GB'

I've trimmed the JSON output below for brevity.

Expected Behavior

GET /extras/object-changes/
  "results": [
    {
      "id": 278,
      "time": "2018-09-19T08:30:08.073529+01:00",
      "changed_object": {
        "id": 6,
      },
      "object_data": {
        "last_updated": "2018-09-19T08:30:08.055212+01:00",
      },
GET /circuits/circuits/
  "results": [
    {
      "id": 6,
      "last_updated": "2018-09-19T08:30:08.055212+01:00"
    },

Observed Behavior

GET /extras/object-changes/
  "results": [
    {
      "id": 278,
      "time": "2018-09-19T08:30:08.073529+01:00",
      "changed_object": {
        "id": 6,
      },
      "object_data": {
        "last_updated": "2018-09-19T07:30:08.055Z",
      },
GET /circuits/circuits/
  "results": [
    {
      "id": 6,
      "last_updated": "2018-09-19T08:30:08.055212+01:00"
    },
Originally created by @ghost on GitHub (Sep 19, 2018). ### Environment * Python version: 3.4.9 * NetBox version: 2.4.4 ### Steps to Reproduce To reproduce, set a non-UTC timezone and compare the outputs of GET /extras/object-changes/?limit=100000 GET /circuits/circuits/ The "last_updated" JSON field returned by the /extras/object-changes/ and /circuits/circuits/ API calls use different timezones when representing the same bit of data. The times shown are correct, but are displayed inconsistently. We use BST (UTC+1), so normally timezones appear as +01:00 at this point in the year. configuration.py has TIME_ZONE = 'GB' I've trimmed the JSON output below for brevity. ### Expected Behavior ``` GET /extras/object-changes/ "results": [ { "id": 278, "time": "2018-09-19T08:30:08.073529+01:00", "changed_object": { "id": 6, }, "object_data": { "last_updated": "2018-09-19T08:30:08.055212+01:00", }, ``` ``` GET /circuits/circuits/ "results": [ { "id": 6, "last_updated": "2018-09-19T08:30:08.055212+01:00" }, ``` ### Observed Behavior ``` GET /extras/object-changes/ "results": [ { "id": 278, "time": "2018-09-19T08:30:08.073529+01:00", "changed_object": { "id": 6, }, "object_data": { "last_updated": "2018-09-19T07:30:08.055Z", }, ``` ``` GET /circuits/circuits/ "results": [ { "id": 6, "last_updated": "2018-09-19T08:30:08.055212+01:00" }, ```
adam closed this issue 2025-12-29 17:21:30 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 28, 2018):

The time in the object data is a static snapshot of the object at a point in time which will never change, whereas the other instances are rendered on-demand and within the context of the current server configuration. I think it makes sense to keep the serialized time in UTC to avoid any complications in the comparison of times should the server timezone be changed.

@jeremystretch commented on GitHub (Sep 28, 2018): The time in the object data is a static snapshot of the object at a point in time which will never change, whereas the other instances are rendered on-demand and within the context of the current server configuration. I think it makes sense to keep the serialized time in UTC to avoid any complications in the comparison of times should the server timezone be changed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2016