Set-up
I'm trying to run unit tests in Django.
pipenv run python manage.py test test_module.tests.test_application.ExampleTest
I'm getting the following error:
Traceback (most recent call last):
File "C:\Users\Dom_W\Documents\Development\Projects\project_test\data_load_api_functions\tests\test_deepcrawl_api.py", line 210, in setUp
print(list(User.objects.all()))
File "C:\Users\Dom_W\.virtualenvs\example-project-n37Jnk2\lib\site-packages\django\db\models\query.py", line 274, in __iter__
self._fetch_all()
File "C:\Users\Dom_W\.virtualenvs\example-project-n37Jnk2\lib\site-packages\django\db\models\query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\Dom_W\.virtualenvs\example-project-n37Jnk2\lib\site-packages\django\db\models\query.py", line 55, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "C:\Users\Dom_W\.virtualenvs\example-project-n37Jnk2\lib\site-packages\django\db\models\sql\compiler.py", line 1130, in execute_sql
return list(result)
File "C:\Users\Dom_W\.virtualenvs\example-project-n37Jnk2\lib\site-packages\django\db\models\sql\compiler.py", line 1509, in cursor_iter
for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
File "C:\Users\Dom_W\.virtualenvs\example-project-n37Jnk2\lib\site-packages\django\db\models\sql\compiler.py", line 1509, in <lambda>
for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
File "C:\Users\Dom_W\.virtualenvs\example-project-n37Jnk2\lib\site-packages\django\db\utils.py", line 96, in inner
return func(*args, **kwargs)
File "C:\Users\Dom_W\.virtualenvs\example-project-n37Jnk2\lib\site-packages\django\db\backends\postgresql\utils.py", line 9, in utc_tzinfo_factory
raise AssertionError("database connection isn't set to UTC")
AssertionError: database connection isn't set to UTC
I think it might've started because of the switch to BST, but now despite forcing timezone I can't get Django to recognise it.
What I've tried
I set the default Postgres timezone to UTC in postgresql.conf
That did nothing so I inspected the function which is responsible:
def utc_tzinfo_factory(offset):
if offset != 0:
raise AssertionError("database connection isn't set to UTC")
return utc
And discovered it's being given a datetime.timedelta
with a value of 0:00:00
which then causes this line to fail:
if offset != 0:
Why isn't it receiving an integer? And how on earth can I fix this?
If I comment out the line, then it all just works fine... But otherwise there is some sort of timezone mismatch.
Env
- Windows 10
- Django: 2.2
- Postgresql: 13