core: bump django from 4.1.7 to 4.2 (#5151)

* core: bump django from 4.1.7 to 4.2

Bumps [django](https://github.com/django/django) from 4.1.7 to 4.2.
- [Release notes](https://github.com/django/django/releases)
- [Commits](https://github.com/django/django/compare/4.1.7...4.2)

---
updated-dependencies:
- dependency-name: django
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* upgrade to psycopg3, use custom engine for prometheus metrics

See https://github.com/korfuri/django-prometheus/issues/350

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* make scripts use pscopg3

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
dependabot[bot] 2023-04-11 15:00:27 +02:00 committed by GitHub
parent 6dd2e2b85f
commit 18a4eac527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 959 additions and 769 deletions

View File

@ -98,7 +98,7 @@ def traces_sampler(sampling_context: dict) -> float:
def before_send(event: dict, hint: dict) -> Optional[dict]:
"""Check if error is database error, and ignore if so"""
# pylint: disable=no-name-in-module
from psycopg2.errors import Error
from psycopg.errors import Error
ignored_classes = (
# Inbuilt types

View File

View File

@ -0,0 +1,21 @@
"""Database engine that uses prometheus exporter"""
from django.db.backends.postgresql import base
from django_prometheus.db.common import DatabaseWrapperMixin, ExportingCursorWrapper
class DatabaseFeatures(base.DatabaseFeatures):
"""Our database has the exact same features as the base one."""
class DatabaseWrapper(DatabaseWrapperMixin, base.DatabaseWrapper):
"""Database wrapper which exports metrics to prometheus"""
def get_connection_params(self):
conn_params = super().get_connection_params()
conn_params["cursor_factory"] = ExportingCursorWrapper(base.Cursor, self.alias, self.vendor)
return conn_params
def create_cursor(self, name=None):
# cursor_factory is a kwarg to connect() so restore create_cursor()'s
# default behavior
return base.DatabaseWrapper.create_cursor(self, name=name)

View File

@ -270,7 +270,7 @@ CHANNEL_LAYERS = {
DATABASES = {
"default": {
"ENGINE": "django_prometheus.db.backends.postgresql",
"ENGINE": "authentik.root.db_engine",
"HOST": CONFIG.y("postgresql.host"),
"NAME": CONFIG.y("postgresql.name"),
"USER": CONFIG.y("postgresql.user"),

View File

@ -6,7 +6,7 @@ from inspect import getmembers, isclass
from pathlib import Path
from typing import Any
from psycopg2 import connect
from psycopg import connect
from structlog.stdlib import get_logger
from authentik.lib.config import CONFIG

View File

@ -5,7 +5,7 @@ from sys import exit as sysexit
from time import sleep
from urllib.parse import quote_plus
from psycopg2 import OperationalError, connect
from psycopg import OperationalError, connect
from redis import Redis
from redis.exceptions import RedisError

1697
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -141,7 +141,7 @@ lxml = "*"
opencontainers = { extras = ["reggie"], version = "*" }
packaging = "*"
paramiko = "*"
psycopg2-binary = "*"
psycopg = { extras = ["binary"], version = "*" }
pycryptodome = "*"
pyjwt = "*"
python = "^3.11"