From 74e12f8d446562789593c192f8be08c980b22a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C5=9F=C4=B1k=20Kaplan?= Date: Sat, 12 Oct 2024 23:12:16 +0300 Subject: [PATCH] Force evaluation of reverse_lazy urls in set_query_parameters. Fixes #1311 Passing reverse_lazy url to SpectacularRedocView errors because set_query_parameters calls urlls.parse.urlparse on url which may not be a string but a 'django.utils.functional.lazy..__proxy__'. Forcing url to be string fixes this issue. --- drf_spectacular/plumbing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/drf_spectacular/plumbing.py b/drf_spectacular/plumbing.py index cf50eb4d..2f721250 100644 --- a/drf_spectacular/plumbing.py +++ b/drf_spectacular/plumbing.py @@ -1280,6 +1280,7 @@ def build_mock_request(method, path, view, original_request, **kwargs): def set_query_parameters(url, **kwargs) -> str: """ deconstruct url, safely attach query parameters in kwargs, and serialize again """ + url = str(url) # Force evaluation of reverse_lazy urls scheme, netloc, path, params, query, fragment = urllib.parse.urlparse(url) query = urllib.parse.parse_qs(query) query.update({k: v for k, v in kwargs.items() if v is not None})