-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
TypeError __str__ returned non-string (type PosixPath) /debug_toolbar/templates/debug_toolbar/panels/staticfiles.html #2002
Comments
Can you share more information about your project? This isn't something we've come across elsewhere. We'd want to know what your static file was and what your installed apps and middlewares are? |
Sure. After switching to ASGI and installing uvicorn, I noticed the event. Legend:
Look for the line {{ staticfile|stringformat:"s" }} is shown on.
|
Whoops, I meant I'd like to reproduce this with one of my applications. I'll see if using uvicorn and asgi with the example app reproduces it, but I may need you to create a reproducible example otherwise. |
Let me know. |
@dougwmorrow yeah, I wasn't able to reproduce this on my project. Any chance you can help create a minimal reproducible example? |
Will look into it. |
This is potentially broken. I don't immediately see why you'd want to use a I'd appreciate a test case, the fix would be to |
@tim-schilling Thanks for waiting. I was getting runners high working on my own project. I found the root cause. 3 files of mine showed up as PosixPath objects. I needed to update my vendor files from context_processors.py as seen below. Essentially, ensure x.relative_to(static_dir) is a string. static_dir = settings.BASE_DIR / "static" No updates are needed for debug_toolbar/panels/staticfiles.html. Let me know if you need any additional information. Feel free to close this out. |
I have pushed a fix in #2021 but didn't manage to construct a test for this just yet. @dougwmorrow If you could test the fix that would be great. Adding |
@matthiask I've tested 2021 push.
The other suggestions were also added to the file.
I plan to update my file paths and so on, but I hope this level of clarity helps. I reverted the for loop in staticfiles.html back to it's original state. Everything looks good. |
Thank you! I'm grateful for the additional confirmation that the updated code works. |
django-debug-toolbar: 4.4.6
I'm just providing a solution to an event I came across. Line 29 for /debug_toolbar/templates/debug_toolbar/panels/staticfiles.html needs to have {{ staticfile }} updated to {{ staticfile|stringformat:"s" }}
Below is the event that happened.
When running uvicorn project.asgi:application --host 127.0.0.1 --port 8001 and then loading 127.0.0.1:8001 in a new web browser, the TypeError str returned non-string (type PosixPath). Specifically focusing on {{ staticfile }}. I updated {{ staticfile }} to {{ staticfile|stringformat:"s" }} and that resolved the TypeError.
Thanks!
The text was updated successfully, but these errors were encountered: