Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #31638 -- Add (failing) test to show timezone problem with Now() #12991

Closed

Conversation

matthijskooijman
Copy link
Contributor

@matthijskooijman matthijskooijman commented May 28, 2020

This is a testcase to show a problem with db.models.functions.Now. For full details, see ticket-31638.

Below, the test output with various setups (output was slightly redacted to remove unnecessary cruft from the output).

Sqlite without database TIME_ZONE

$ ./runtests.py db_functions.datetime.test_now --settings test_sqlite
.db_functions.datetime.test_now.NowTests.test_with_use_tz
TIME_ZONE: America/Chicago connection: UTC
now: 2020-05-28 11:14:08.703968+00:00 written: 2020-05-28 11:14:08.697957+00:00 published: 2020-05-28 11:14:08+00:00

.db_functions.datetime.test_now.NowTests.test_without_use_tz
TIME_ZONE: America/Chicago connection: America/Chicago
now: 2020-05-28 06:14:08.714462 written: 2020-05-28 06:14:08.712672 published: 2020-05-28 11:14:08

F
======================================================================
FAIL: test_without_use_tz (db_functions.datetime.test_now.NowTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/matthijs/docs/src/upstream/django/django/test/utils.py", line 381, in inner
    return func(*args, **kwargs)
  File "/home/matthijs/docs/src/upstream/django/tests/db_functions/datetime/test_now.py", line 82, in test_without_use_tz
    self.compare_db_and_py_now()
  File "/home/matthijs/docs/src/upstream/django/tests/db_functions/datetime/test_now.py", line 73, in compare_db_and_py_now
    self.assertSequenceEqual(Article.objects.filter(written__gt=Now() - timedelta(minutes=1)), [a])
AssertionError: Sequences differ: <QuerySet []> != [<Article: Article object (1)>]

Sqlite with database TIME_ZONE

This uses the following db config (it also sets USE_TZ, since otherwise TIME_ZONE is not accepted):

  DATABASES = {                                                                                                           
      'default': {                                                                                                        
          'ENGINE': 'django.db.backends.sqlite3',                                                                         
          'TIME_ZONE': 'Europe/Amsterdam',                                                                                
      },                                                                                                                  
      'other': {                                                                                                          
          'ENGINE': 'django.db.backends.sqlite3',                                                                         
      }                                                                                                                   
  }                                                                                                                       
  USE_TZ=True  
$ ./runtests.py db_functions.datetime.test_now.NowTests.test_with_use_tz --settings test_sqlite
db_functions.datetime.test_now.NowTests.test_with_use_tz
TIME_ZONE: America/Chicago connection: Europe/Amsterdam
now: 2020-05-28 11:16:58.623102+00:00 written: 2020-05-28 13:16:58.616318+02:00 published: 2020-05-28 11:16:58+02:00

F
======================================================================
FAIL: test_with_use_tz (db_functions.datetime.test_now.NowTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/matthijs/docs/src/upstream/django/django/test/utils.py", line 381, in inner
    return func(*args, **kwargs)
  File "/home/matthijs/docs/src/upstream/django/tests/db_functions/datetime/test_now.py", line 86, in test_with_use_tz
    self.compare_db_and_py_now()
  File "/home/matthijs/docs/src/upstream/django/tests/db_functions/datetime/test_now.py", line 71, in compare_db_and_py_now
    self.assertSequenceEqual(Article.objects.filter(written__lte=Now() + timedelta(minutes=1)), [a])
AssertionError: Sequences differ: <QuerySet []> != [<Article: Article object (1)>]

Mysql (5.5.5-10.3.22-MariaDB-0ubuntu0.19.10.1)

$ ./runtests.py db_functions.datetime.test_now --settings test_mysql
.db_functions.datetime.test_now.NowTests.test_with_use_tz
TIME_ZONE: America/Chicago connection: UTC
global.time_zone: SYSTEM session.time_zone SYSTEM system_time_zone: CEST
now: 2020-05-28 11:15:14.890671+00:00 written: 2020-05-28 11:15:14.887143+00:00 published: 2020-05-28 13:15:14+00:00

Fdb_functions.datetime.test_now.NowTests.test_without_use_tz
TIME_ZONE: America/Chicago connection: America/Chicago
global.time_zone: SYSTEM session.time_zone SYSTEM system_time_zone: CEST
now: 2020-05-28 06:15:14.908754 written: 2020-05-28 06:15:14.903515 published: 2020-05-28 13:15:14

F
======================================================================
FAIL: test_with_use_tz (db_functions.datetime.test_now.NowTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/matthijs/docs/src/upstream/django/django/test/utils.py", line 381, in inner
    return func(*args, **kwargs)
  File "/home/matthijs/docs/src/upstream/django/tests/db_functions/datetime/test_now.py", line 86, in test_with_use_tz
    self.compare_db_and_py_now()
  File "/home/matthijs/docs/src/upstream/django/tests/db_functions/datetime/test_now.py", line 73, in compare_db_and_py_now
    self.assertSequenceEqual(Article.objects.filter(written__gt=Now() - timedelta(minutes=1)), [a])
AssertionError: Sequences differ: <QuerySet []> != [<Article: Article object (3)>]

======================================================================
FAIL: test_without_use_tz (db_functions.datetime.test_now.NowTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/matthijs/docs/src/upstream/django/django/test/utils.py", line 381, in inner
    return func(*args, **kwargs)
  File "/home/matthijs/docs/src/upstream/django/tests/db_functions/datetime/test_now.py", line 82, in test_without_use_tz
    self.compare_db_and_py_now()
  File "/home/matthijs/docs/src/upstream/django/tests/db_functions/datetime/test_now.py", line 73, in compare_db_and_py_now
    self.assertSequenceEqual(Article.objects.filter(written__gt=Now() - timedelta(minutes=1)), [a])
AssertionError: Sequences differ: <QuerySet []> != [<Article: Article object (4)>]

@matthijskooijman matthijskooijman changed the title Add (failing) test to show timezone problem with Now() Refs ##31638 -- Add (failing) test to show timezone problem with Now() May 28, 2020
@matthijskooijman matthijskooijman changed the title Refs ##31638 -- Add (failing) test to show timezone problem with Now() Refs #31638 -- Add (failing) test to show timezone problem with Now() May 28, 2020
@felixxm
Copy link
Member

felixxm commented Jun 4, 2020

Closing per ticket.

@felixxm felixxm closed this Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants