django-pgconnection
django-pgconnection copied to clipboard
Using with Django 4.1 runserver raises exceptions
This may be related to #5
Setting up django-pgconnection with Django 4.1 causes the following exception when runserver is run:
Traceback (most recent call last):
File "/path/to/.pyenv/versions/3.10.4/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/path/to/.pyenv/versions/3.10.4/lib/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 137, in inner_run
self.check_migrations()
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/core/management/base.py", line 564, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/db/migrations/loader.py", line 58, in __init__
self.build_graph()
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/db/migrations/loader.py", line 235, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
if self.has_table():
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/db/backends/base/base.py", line 323, in cursor
return self._cursor()
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/db/backends/base/base.py", line 299, in _cursor
self.ensure_connection()
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
self.connect()
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/db/backends/base/base.py", line 247, in connect
self.check_settings()
File "/path/to/project/.direnv/python-3.10.4/lib/python3.10/site-packages/django/db/backends/base/base.py", line 271, in check_settings
if self.settings_dict["TIME_ZONE"] is not None and not settings.USE_TZ:
KeyError: 'TIME_ZONE'
@shangxiao if you are using dango-pgconnection for pgtrigger or pghistory, the latest version of those libraries drops the pgconnection dependency. I'd recommend upgrading and removing the pgconnection config
A lot of pgconnection's functionality is available in Django connection hooks (see #7 ), and I will likely archive this library.
FYI I believe the issue is likely caused by https://github.com/django/django/commit/13378ad95206a96c3d1d261eb738032468a7acc1 , as part of https://github.com/django/django/pull/15490 . The logic to fill in default arguments in a connection's settings_dict was moved, and I think this interacts badly with the _Databases class.