#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 by , 9 years ago
comment:2 by , 9 years ago
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 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Thanks for clarifying -- thank makes sense. Care to submit a patch?
comment:5 by , 9 years ago
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 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 9 years ago
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.
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.