U
U
un1t2016-09-13 18:39:52
PostgreSQL
un1t, 2016-09-13 18:39:52

Django + Postgres: Why is there a "database connection isn't set to UTC" error?

settings.py

TIME_ZONE = 'Asia/Yekaterinburg'
USE_TZ = True

$ cat /etc/timezone 
Asia/Yekaterinburg
$ ll /etc/localtime 
/etc/localtime -> /usr/share/zoneinfo/Asia/Yekaterinburg

File "/home/user/myproject/apps/core/dev.py", line 22, in fill_dev_db
    list(Offer.objects.all())
  File "/home/user/myproject/python3/lib/python3.5/site-packages/django/db/models/query.py", line 256, in __iter__
    self._fetch_all()
  File "/home/user/myproject/python3/lib/python3.5/site-packages/django/db/models/query.py", line 1087, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/home/user/myproject/python3/lib/python3.5/site-packages/django/db/models/query.py", line 65, in __iter__
    for row in compiler.results_iter(results):
  File "/home/user/myproject/python3/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 792, in results_iter
    for rows in results:
  File "/home/user/myproject/python3/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1238, in cursor_iter
    sentinel):
  File "/home/user/myproject/python3/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1237, in <lambda>
    for rows in iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
  File "/home/user/myproject/python3/lib/python3.5/site-packages/django/db/utils.py", line 101, in inner
    return func(*args, **kwargs)
  File "/home/user/myproject/python3/lib/python3.5/site-packages/django/db/backends/postgresql/utils.py", line 6, in utc_tzinfo_factory
    raise AssertionError("database connection isn't set to UTC")

An exception is generated from this function, but grep or backtrace did not give an answer from where it is called.
# django/db/backends/postgresql/utils.py
def utc_tzinfo_factory(offset):
    if offset != 0:
        raise AssertionError("database connection isn't set to UTC")
    return utc

Django 1.10.1
Ubuntu 16.04
Postgres 9.5.4
UPDATE:
Similar version of postgres is not playable in docker.
In vagrant installed a similar version of ubuntu and postgres - not reproducible.
On my Ubuntu 14.04 / Postgres 9.3 machine - not playable.
On that wheelbarrow it is stable under different accounts, I tried to reinstall postgres - it did not help. If the application remotely connects to this postgres, it will also reproduce.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question