Problem/Motivation

Since #3009377: Replace drupal_get_user_timezone with a date_default_timezone_get() and an event listener the datelist element uses the native date_default_timezone_get function to get the default timezone for elements. This can result in non-determinism if caches are flushed via the Admin UI versus CLI (drush).

Steps to reproduce

On a hosting environment whose server timezone is UTC and whose site timezone (system.date.yml) is set to America/New_York...

  1. Flush the cache via the GUI - notice that datelist elements have a default timezone of America/New_York
  2. Flush the cache via Drush - notice that datelist elements have a default timezone of UTC

This can lead to some hard to diagnose data quality problems for downstream users - where the persisted timezone is random.

See https://github.com/drush-ops/drush/issues/6350 for a possible fix in Drush -- but I think the potential for nondeterminism still exists even if the drush issue is resolved.

Proposed resolution

Do what was done in #3087606: Datetime::getInfo() caches user's timezone causing unpredictable timestamps. and don't set the default timezone in the element's getInfo() callback, since that's cached. The default timezone to use is dependent on the user and the site's configuration.

Remaining tasks

Review

User interface changes

NA

Introduced terminology

NA

API changes

NA

Data model changes

NA

Release notes snippet

NA

Issue fork drupal-3545132

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

luke.leber created an issue. See original summary.

luke.leber’s picture

Issue summary: View changes

bkosborne made their first commit to this issue’s fork.

bkosborne’s picture

I think the default timezone should not be in the info data at all since it gets cached. A similar issue was found in the (much more widely used) Datetime element in [#13398554] and it was addressed there by pulling it out of the info data. Let's do the same here. I submitted a quick MR to see what fails, but I think we can add a test for it too.

bkosborne’s picture

bkosborne’s picture

Issue summary: View changes
Status: Active » Needs review

Added a test (same one from Datetime's test). Ready for review.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative, +Bug Smash Initiative

Re-ran the failing tests and they were all random.

Ran the test-only feature and got https://git.drupalcode.org/issue/drupal-3545132/-/jobs/7875619 which properly shows the bug.

Reviewing #3087606: Datetime::getInfo() caches user's timezone causing unpredictable timestamps. and this does seem inline with that.

LGTM

luke.leber’s picture

+1 RTBC

I ran a quick test after removing https://github.com/drush-ops/drush/issues/6350#issuecomment-3275964221 and the proper timezone seems to be used in all cases now.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

alexpott’s picture

Version: main » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 6e1cc4a09c1 to main and 7806a3ff92b to 11.x and 53bea0b5845 to 11.3.x. Thanks!

Nice find and fix. Backported to 11.3.x as a safe backport.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed 53bea0b5 on 11.3.x
    fix: #3545132 Datelist element has nondeterministic timezone
    
    By: luke....

  • alexpott committed 7806a3ff on 11.x
    fix: #3545132 Datelist element has nondeterministic timezone
    
    By: luke....

  • alexpott committed 6e1cc4a0 on main
    fix: #3545132 Datelist element has nondeterministic timezone
    
    By: luke....

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.