AssertionError: database connection isn’t set to UTC

The release of psycopg2 version 2.9 caused this error as explained in this GitHub issue:

https://github.com/psycopg/psycopg2/issues/1293#issuecomment-862835147

Psycopg 2.9 changed the value passed to tzinfo_factory from an int to a timedelta. Django 2.2 (possibly newer but I’m on 2.2) has a check for offset == 0 and since timedelta(0) != 0 it goes boom.

One solution is to downgrade psycopg2 (or psycopg2-binary if you are using the stand-alone package) below 2.9 (e.g. psycopg2>=2.8,<2.9) in your requirements file.

For instance you can downgrade to 2.8.6 using:

pip install psycopg2==2.8.6

or

pip install psycopg2-binary==2.8.6

If you’re using poetry, you can do poetry add psycopg2@2.8.6 to fix your version to 2.8.6.

psycopg2 release history

Leave a Comment