From ebd9601fe27ea0c443c7ceaa9ac3a4e2aaca2a82 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Wed, 4 Oct 2023 18:39:29 +0200 Subject: [PATCH] MT#58450 Support and use django-structlog versions >=6.0 As of django-structlog v6.0.0, our django application fails with: | Traceback (most recent call last): | File "/var/lib/repoapi/venv_prod/lib/python3.9/site-packages/django/utils/module_loading.py", line 20, in import_string | return getattr(module, class_name) | AttributeError: module 'django_structlog.middlewares' has no attribute 'CeleryMiddleware' Quoting from https://django-structlog.readthedocs.io/en/latest/upgrade_guide.html#upgrading-to-6-0: | (If you use celery) Make sure you use DJANGO_STRUCTLOG_CELERY_ENABLED = True | | It is only applicable if you use celery integration. | | django_structlog.middlewares.CeleryMiddleware has been remove in favor of a django settings. | | MIDDLEWARE += [ | "django_structlog.middlewares.RequestMiddleware", | # "django_structlog.middlewares.CeleryMiddleware", # <- remove this | ] | | DJANGO_STRUCTLOG_CELERY_ENABLED = True # <-- add this Instead of forcing usage of an older django-structlog version, let's make sure we have 6.0 or newer and update configuration accordingly. Change-Id: I0449c05db682ace22438b8b0ad8d8a4a1dfca71a --- repoapi/settings/common.py | 3 ++- requirements/common.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/repoapi/settings/common.py b/repoapi/settings/common.py index 68e7732..42684b0 100644 --- a/repoapi/settings/common.py +++ b/repoapi/settings/common.py @@ -60,9 +60,10 @@ MIDDLEWARE = ( "django.middleware.clickjacking.XFrameOptionsMiddleware", "django.middleware.security.SecurityMiddleware", "django_structlog.middlewares.RequestMiddleware", - "django_structlog.middlewares.CeleryMiddleware", ) +DJANGO_STRUCTLOG_CELERY_ENABLED = True + ROOT_URLCONF = "repoapi.urls" LOGIN_URL = "rest_framework:login" LOGOUT_URL = "rest_framework:logout" diff --git a/requirements/common.txt b/requirements/common.txt index dd88bcf..8ebdce0 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -10,7 +10,7 @@ django-extensions django-filter django-import-export>=3.0 django-jsonify -django-structlog +django-structlog>=6.0 django-timezone-field djangorestframework>=3.6 djangorestframework-api-key==2.*