Skip to content

Compatibility status with Psycopg v3 #36

@cro

Description

@cro

Greetings,

I have an existing Django project I am retrofitting to use Channels and channels_postgres with, and it uses Psycopg version 3.

I had a toy project I started from scratch to experiment with Channels and channels_postgres. The toy project worked fine, but the retrofitted project was throwing tracebacks (see below) in the channels layers. django-admin startproject defaults to v3.

I can make the tracebacks go away if I remove Psycopg v3 and replace it with v2.

I see the reference to django.db.backends.postgresql_psycopg2 in the documentation. Docs for recent versions of Django seem to imply that you can use django.db.backends.postgresql and Django will do the "right thing" with respect to the available database driver.

Is this a known issue? Even though I explicitly replaced the channels ENGINE with django.db.backends.postgresql_psycopg2 the Django database subsystem seems to ignore it and load v3.

I took a quick stab at attempting to remove aiopg and replace it with Psycopg 3 since version 3 supports async now, but it is proving to be more effort than I thought. I also was unsure if you would accept a PR because of potential compatibility mismatches across the version matrix.

Traceback (most recent call last):
  File "/Users/cro/src/odmn/.venv/lib/python3.13/site-packages/django/core/handlers/exception.py", line 42, in inner
    response = await get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cro/src/odmn/.venv/lib/python3.13/site-packages/django/core/handlers/base.py", line 253, in _get_response_async
    response = await wrapped_callback(
               
  File "/Users/cro/.local/share/uv/python/cpython-3.13.2-macos-aarch64-none/lib/python3.13/asyncio/futures.py", line 286, in __await__
    yield self  # This tells Task to wait for completion.
    ^^^^^^^^^^
  File "/Users/cro/.local/share/uv/python/cpython-3.13.2-macos-aarch64-none/lib/python3.13/asyncio/tasks.py", line 375, in __wakeup
    future.result()
    ^^^^^^^^^^^^^^^
  File "/Users/cro/.local/share/uv/python/cpython-3.13.2-macos-aarch64-none/lib/python3.13/asyncio/futures.py", line 199, in result
    raise self._exception.with_traceback(self._exception_tb)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cro/src/odmn/odmn/core/views.py", line 173, in eventtest
    async_to_sync(channel_layer.group_send)("chat",
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cro/.local/share/uv/python/cpython-3.13.2-macos-aarch64-none/lib/python3.13/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/cro/.local/share/uv/python/cpython-3.13.2-macos-aarch64-none/lib/python3.13/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
    ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cro/src/odmn/.venv/lib/python3.13/site-packages/channels_postgres/core.py", line 266, in group_send
    _, pool = await self.get_pool()
              ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cro/src/odmn/.venv/lib/python3.13/site-packages/channels_postgres/core.py", line 76, in get_pool
    pool = await aiopg.create_pool(**self.db_params, **self.async_lib_config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cro/src/odmn/.venv/lib/python3.13/site-packages/aiopg/pool.py", line 300, in from_pool_fill
    await self._fill_free_pool(False)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cro/src/odmn/.venv/lib/python3.13/site-packages/aiopg/pool.py", line 336, in _fill_free_pool
    conn = await connect(
                 
  File "/Users/cro/src/odmn/.venv/lib/python3.13/site-packages/aiopg/connection.py", line 65, in connect
    connection = Connection(
                 
  File "/Users/cro/src/odmn/.venv/lib/python3.13/site-packages/aiopg/connection.py", line 760, in __init__
    self._conn = psycopg2.connect(dsn, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cro/src/odmn/.venv/lib/python3.13/site-packages/psycopg2/__init__.py", line 121, in connect
    dsn = _ext.make_dsn(dsn, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cro/src/odmn/.venv/lib/python3.13/site-packages/psycopg2/extensions.py", line 167, in make_dsn
    parse_dsn(dsn)
    ^^^^^^^^^^^^^^

Exception Type: ProgrammingError at /core/eventtest/
Exception Value: invalid dsn: invalid connection option "context"```

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions