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

Django debug toolbar is not working #1457

Closed
lucasmarchd01 opened this issue May 15, 2024 · 7 comments · Fixed by #1464
Closed

Django debug toolbar is not working #1457

lucasmarchd01 opened this issue May 15, 2024 · 7 comments · Fixed by #1464
Labels
bug Something isn't working dependencies Pull requests that update a dependency file

Comments

@lucasmarchd01
Copy link
Contributor

I just noticed that while working in my development environment (devcontainer setup), the Django debug toolbar doesn't show. Perhaps this was as a result of #1454?

@lucasmarchd01
Copy link
Contributor Author

lucasmarchd01 commented May 15, 2024

I've got it to work by running request.META["REMOTE_ADDR"] to one of our views, which has exposed the port 172.24.0.4 as the IP host in the django container. So if I add this IP to INTERNAL_IPS it fixes the issue, but this solution is hardcoding the IP address which isn't really useful. Is there a way of making this dynamic in settings.py?

@lucasmarchd01
Copy link
Contributor Author

This works too, but not sure if it will be the same for everyone:

if DEBUG:
    import socket
    ip = socket.gethostbyname(socket.gethostname())
    INTERNAL_IPS += [ip[:-1] + "4"]
    INSTALLED_APPS.append("debug_toolbar")
    # debug toolbar must be inserted as early in the middleware as possible
    MIDDLEWARE.insert(0, "debug_toolbar.middleware.DebugToolbarMiddleware")

@dchiller
Copy link
Contributor

I was frustrated by this too the other day!

@dchiller
Copy link
Contributor

Was just about to post the same thing:

    import socket

    INTERNAL_IPS = [
        ".".join(socket.gethostbyname("host.docker.internal").split(".")[:-1]) + ".1"
    ]

@dchiller
Copy link
Contributor

What's odd to me is that this is similar to what the debug_toolbar already has in its callback:

https://github.com/jazzband/django-debug-toolbar/blob/7271cac9eacb7870200d6bc965c84eb91ba36714/debug_toolbar/middleware.py#L19-L38

@lucasmarchd01
Copy link
Contributor Author

Interesting. I remember when setting this up seeing this warning in their documentation:
django-commons/django-debug-toolbar#1854

But now it's gone. I think their solution assumed that the docker IP would always end with 1, but it ends in 4 for our (or my) case which is why it didn't work.

@lucasmarchd01 lucasmarchd01 changed the title Django debug toolbar not available Django debug toolbar is not working May 15, 2024
@lucasmarchd01
Copy link
Contributor Author

Now, while using the debug toolbar to try and see how many SQL queries are being made, I get the following error:

AttributeError at /
'Connection' object has no attribute 'status'

I think this is probably linked to django-commons/django-debug-toolbar#1754. We have django_debug_toolbar = "3.8.1" in our dev dependencies and psycopg 3.1.18 which are incompatible.

@lucasmarchd01 lucasmarchd01 added bug Something isn't working dependencies Pull requests that update a dependency file labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants