Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing reverse_lazy url to SpectacularRedocView errors. #1311

Closed
isik-kaplan opened this issue Oct 12, 2024 · 2 comments
Closed

Passing reverse_lazy url to SpectacularRedocView errors. #1311

isik-kaplan opened this issue Oct 12, 2024 · 2 comments

Comments

@isik-kaplan
Copy link
Contributor

Describe the bug

Passing reverse_lazy url to SpectacularRedocView errors.

I've chased down the issue to drf_spectacular.plumbing.set_query_parameters which uses urllib.parse.urlparse which needs a string to work.

To Reproduce
It would be most helpful to provide a small snippet to see how the bug was provoked.

-> scheme, netloc, path, params, query, fragment = urllib.parse.urlparse(url)
(Pdb) from django.urls import reverse_lazy
(Pdb) url = reverse_lazy('rest:v0:api-root')  # Change the url name here to an actual url in the project
(Pdb) url
'/v0/'
(Pdb) type(url)
<class 'django.utils.functional.lazy.<locals>.__proxy__'>
(Pdb) urllib.parse.urlparse(str(url))
ParseResult(scheme='', netloc='', path='/v0/', params='', query='', fragment='')
(Pdb) urllib.parse.urlparse(url)
*** AttributeError: '__proxy__' object has no attribute 'decode'
(Pdb)

Expected behavior

If you change

scheme, netloc, path, params, query, fragment = urllib.parse.urlparse(url)
# to
scheme, netloc, path, params, query, fragment = urllib.parse.urlparse(str(url))
# forcing the evaluation of the lazy url 

it works as expected

isik-kaplan added a commit to isik-kaplan/drf-spectacular that referenced this issue Oct 12, 2024
…franzel#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.<locals>.__proxy__'. Forcing url to be string fixes this issue.
@isik-kaplan
Copy link
Contributor Author

I've attached a very tiny PR that fixes this issue.

@autumn-ma
Copy link

bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants