Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#25845 closed Bug (fixed)

False timezone offset warnings in admin if a custom base template doesn't set data-admin-utc-offset

Reported by: Sven Grunewaldt Owned by: Sven Grunewaldt
Component: contrib.admin Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django 1.9 introduced a new data attribute on the body tag in the Django admin base template:
https://github.com/django/django/commit/8eeb566aca33600d272dee5fba59c3445b5b8163

This attribute is read in JavaScript with getAttribute() and checked on !== undefined to determine if it is set:
https://github.com/django/django/commit/8eeb566aca33600d272dee5fba59c3445b5b8163#diff-cb2d960617da7bad9ba5ed3366931159R22

This worked with the previous code, but getAttribute() returns null or "", which never equals undefined. Because of this the following code will run, calculating false offsets between browser time and server time, causing false warnings to appear in the admin date widgets.

More info on getAttribute():
https://developer.mozilla.org/de/docs/Web/API/Element/getAttribute#Notes

I noticed this after upgrading to Django 1.9 while using django-suit, which is missing the attribute on body at the moment:
https://github.com/darklow/django-suit/issues/449

Change History (9)

comment:1 Changed 4 years ago by Tim Graham

Yes, this is documented as a backwards incompatible change in the release notes. I think django-suit needs to add support for Django 1.9 by adding the missing body attribute unless someone has an alternate suggestion.

comment:2 Changed 4 years ago by Sven Grunewaldt

But wasn't the old behavior to not show the warnings if the JavaScript attribute is missing? As far as I can see, django-suit also didn't set the window property __admin_utc_offset__ before. The warnings were not shown, since the JS function addTimezoneWarning() won't do anything if timezoneOffset is not set. The whole check on undefined doesn't make sense to me and looks like a leftover of the previous code.

If the checks were to be replaced by a check on null (and possibly ""), it would behave like before.

comment:3 Changed 4 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

Thanks for clarifying -- thank makes sense. Care to submit a patch?

comment:4 Changed 4 years ago by Emre Yılmaz

comment:5 Changed 4 years ago by Sven Grunewaldt

I already have the bug itself fixed, but I also want to add tests for this, as suggested. Since I have some trouble getting the Django tests to run I will hopefully be able to provide a PR with the fix and tests tomorrow.

comment:6 Changed 4 years ago by Sven Grunewaldt

Owner: changed from nobody to Sven Grunewaldt
Status: newassigned

comment:7 Changed 4 years ago by Sven Grunewaldt

Sorry it took so long... had to figure out how the Selenium tests are done in Django.

PR is open on Github:
https://github.com/django/django/pull/5782

I also signed and submitted the CLA just now.

comment:8 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 9af40f5d:

Fixed #25845 -- Fixed incorrect timezone warnings in custom admin templates.

comment:9 Changed 4 years ago by Tim Graham <timograham@…>

In badeb56:

[1.9.x] Fixed #25845 -- Fixed incorrect timezone warnings in custom admin templates.

Backport of 9af40f5df13801ffadcc5ded7440e4616123959f from master

Note: See TracTickets for help on using tickets.
Back to Top