From 8e9a4ad48fda74352957d300d51a74ae1f28721c Mon Sep 17 00:00:00 2001 From: Manuel Holtgrewe Date: Thu, 20 Jun 2024 11:01:45 +0200 Subject: [PATCH] fix: compatibility with DRF manage.py generateschema (#1440) --- projectroles/views_api.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/projectroles/views_api.py b/projectroles/views_api.py index 54fbf1a8..c87bd050 100644 --- a/projectroles/views_api.py +++ b/projectroles/views_api.py @@ -1,6 +1,7 @@ """REST API views for the projectroles app""" import re +import sys from ipaddress import ip_address, ip_network @@ -257,7 +258,14 @@ class APIProjectContextMixin(ProjectAccessMixin): def get_serializer_context(self, *args, **kwargs): context = super().get_serializer_context(*args, **kwargs) - context['project'] = self.get_project(request=context['request']) + if ( + not context['request'] + and not getattr(self, 'request') + and sys.argv[1:2] == ["generateschema"] + ): + pass # allow request being unset when running management command + else: + context['project'] = self.get_project(request=context['request']) return context def get_queryset(self):