core: revert django update (#5236)

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

This reverts commit 18a4eac527.

* run unittests with postgres 11 and 12

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

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-04-13 14:10:12 +02:00 committed by GitHub
parent 200d6d6adf
commit f84a10b59b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 784 additions and 959 deletions

View File

@ -1,6 +1,11 @@
name: 'Setup authentik testing environment'
description: 'Setup authentik testing environment'
inputs:
postgresql_tag:
description: "Optional postgresql image tag"
default: "12"
runs:
using: "composite"
steps:
@ -24,6 +29,7 @@ runs:
- name: Setup dependencies
shell: bash
run: |
export PSQL_TAG=${{ inputs.postgresql_tag }}
docker-compose -f .github/actions/setup/docker-compose.yml up -d
poetry env use python3.11
poetry install

View File

@ -3,7 +3,7 @@ version: '3.7'
services:
postgresql:
container_name: postgres
image: library/postgres:12
image: library/postgres:${PSQL_TAG:-12}
volumes:
- db-data:/var/lib/postgresql/data
environment:

View File

@ -80,12 +80,21 @@ jobs:
- name: migrate to latest
run: poetry run python -m lifecycle.migrate
test-unittest:
name: test-unittest - PostgreSQL ${{ matrix.psql }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
psql:
- 11-alpine
- 12-alpine
steps:
- uses: actions/checkout@v3
- name: Setup authentik env
uses: ./.github/actions/setup
with:
postgresql_tag: ${{ matrix.psql }}
- name: run unittest
run: |
poetry run make test

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 psycopg.errors import Error
from psycopg2.errors import Error
ignored_classes = (
# Inbuilt types

View File

@ -1,21 +0,0 @@
"""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": "authentik.root.db_engine",
"ENGINE": "django_prometheus.db.backends.postgresql",
"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 psycopg import connect
from psycopg2 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 psycopg import OperationalError, connect
from psycopg2 import OperationalError, connect
from redis import Redis
from redis.exceptions import RedisError

1695
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 = "*"
psycopg = { extras = ["binary"], version = "*" }
psycopg2-binary = "*"
pycryptodome = "*"
pyjwt = "*"
python = "^3.11"