diff --git a/authentik/lib/sentry.py b/authentik/lib/sentry.py index 9f6793df4a..646905e148 100644 --- a/authentik/lib/sentry.py +++ b/authentik/lib/sentry.py @@ -5,7 +5,6 @@ from typing import Any from billiard.exceptions import SoftTimeLimitExceeded, WorkerLostError from celery.exceptions import CeleryError -from channels_redis.core import ChannelFull from django.conf import settings from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation, ValidationError from django.db import DatabaseError, InternalError, OperationalError, ProgrammingError @@ -124,7 +123,6 @@ def before_send(event: dict, hint: dict) -> dict | None: RedisError, ResponseError, # websocket errors - ChannelFull, WebSocketException, LocalProtocolError, # rest_framework error diff --git a/authentik/root/settings.py b/authentik/root/settings.py index 24f56e7b39..bcccdcd579 100644 --- a/authentik/root/settings.py +++ b/authentik/root/settings.py @@ -67,6 +67,7 @@ SHARED_APPS = [ "pgactivity", "pglock", "channels", + "channels_postgres", ] TENANT_APPS = [ "django.contrib.auth", @@ -290,16 +291,6 @@ TEMPLATES = [ ASGI_APPLICATION = "authentik.root.asgi.application" -CHANNEL_LAYERS = { - "default": { - "BACKEND": "channels_redis.pubsub.RedisPubSubChannelLayer", - "CONFIG": { - "hosts": [CONFIG.get("channel.url") or redis_url(CONFIG.get("redis.db"))], - "prefix": "authentik_channels_", - }, - }, -} - # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases @@ -312,6 +303,16 @@ DATABASE_ROUTERS = ( "django_tenants.routers.TenantSyncRouter", ) +CHANNEL_LAYERS = { + "default": { + "BACKEND": "channels_postgres.core.PostgresChannelLayer", + "CONFIG": { + **DATABASES["default"], + "TIME_ZONE": None, + }, + }, +} + # Email # These values should never actually be used, emails are only sent from email stages, which # loads the config directly from CONFIG diff --git a/pyproject.toml b/pyproject.toml index cb84b5854b..5b7af373be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ dependencies = [ "argon2-cffi", "celery", "channels", - "channels-redis", + "channels-postgres", "cryptography", "dacite", "deepmerge", @@ -102,6 +102,7 @@ dev = [ ] [tool.uv.sources] +channels-postgres = { git = "https://github.com/danidee10/channels_postgres.git", branch = "pyscopg3-port" } django-tenants = { git = "https://github.com/rissson/django-tenants.git", branch = "authentik-fixes" } opencontainers = { git = "https://github.com/BeryJu/oci-python", rev = "c791b19056769cd67957322806809ab70f5bead8" } diff --git a/uv.lock b/uv.lock index 58e22fe74a..a0fcbbc4e6 100644 --- a/uv.lock +++ b/uv.lock @@ -171,7 +171,7 @@ dependencies = [ { name = "argon2-cffi" }, { name = "celery" }, { name = "channels" }, - { name = "channels-redis" }, + { name = "channels-postgres" }, { name = "cryptography" }, { name = "dacite" }, { name = "deepmerge" }, @@ -269,7 +269,7 @@ requires-dist = [ { name = "argon2-cffi" }, { name = "celery" }, { name = "channels" }, - { name = "channels-redis" }, + { name = "channels-postgres", git = "https://github.com/danidee10/channels_postgres.git?branch=pyscopg3-port" }, { name = "cryptography" }, { name = "dacite" }, { name = "deepmerge" }, @@ -699,18 +699,14 @@ daphne = [ ] [[package]] -name = "channels-redis" -version = "4.2.1" -source = { registry = "https://pypi.org/simple" } +name = "channels-postgres" +version = "1.0.7" +source = { git = "https://github.com/danidee10/channels_postgres.git?branch=pyscopg3-port#22b86c632304e57f499586a339bf0997507eabbd" } dependencies = [ { name = "asgiref" }, { name = "channels" }, { name = "msgpack" }, - { name = "redis" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/c7/6d/c379c9feea4522cbdb4eba9b3d23a6270ba8cbd94e847b21834d898109d6/channels_redis-4.2.1.tar.gz", hash = "sha256:8375e81493e684792efe6e6eca60ef3d7782ef76c6664057d2e5c31e80d636dd", size = 31152 } -wheels = [ - { url = "https://files.pythonhosted.org/packages/a6/aa/981d08ae9627c3b9d8dd150f0fe644122a351abc1f47bcf53d2bfff80d91/channels_redis-4.2.1-py3-none-any.whl", hash = "sha256:2ca33105b3a04b5a327a9c47dd762b546f30b76a0cd3f3f593a23d91d346b6f4", size = 20487 }, + { name = "psycopg", extra = ["pool"] }, ] [[package]] @@ -2324,6 +2320,9 @@ wheels = [ c = [ { name = "psycopg-c", marker = "implementation_name != 'pypy'" }, ] +pool = [ + { name = "psycopg-pool" }, +] [[package]] name = "psycopg-c" @@ -2331,6 +2330,18 @@ version = "3.2.6" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/2f/f1/367a2429af2b97f6a46dc116206cd3b1cf668fca7ff3c22b979ea0686427/psycopg_c-3.2.6.tar.gz", hash = "sha256:b5fd4ce70f82766a122ca5076a36c4d5818eaa9df9bf76870bc83a064ffaed3a", size = 609304 } +[[package]] +name = "psycopg-pool" +version = "3.2.6" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/cf/13/1e7850bb2c69a63267c3dbf37387d3f71a00fd0e2fa55c5db14d64ba1af4/psycopg_pool-3.2.6.tar.gz", hash = "sha256:0f92a7817719517212fbfe2fd58b8c35c1850cdd2a80d36b581ba2085d9148e5", size = 29770 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/47/fd/4feb52a55c1a4bd748f2acaed1903ab54a723c47f6d0242780f4d97104d4/psycopg_pool-3.2.6-py3-none-any.whl", hash = "sha256:5887318a9f6af906d041a0b1dc1c60f8f0dda8340c2572b74e10907b51ed5da7", size = 38252 }, +] + [[package]] name = "publication" version = "0.0.3"