Skip to content

Admin: install debug_toolbar #9753

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

Merged
merged 4 commits into from
Nov 29, 2022
Merged

Admin: install debug_toolbar #9753

merged 4 commits into from
Nov 29, 2022

Conversation

humitos
Copy link
Member

@humitos humitos commented Nov 22, 2022

This application needs to be installed if we want to enable it later in the web-extra instance. Otherwise, it fails due the static files are not in the manifest.

By installing it by default, collectstatic will find this application and copy these static files and add them in the manifest.

Note this application will only be used if SHOW_DEBUG_TOOLBAR=True, which is False by default.

This application needs to be installed if we want to enable it later in the
`web-extra` instance. Otherwise, it fails due the static files are not in the
manifest.

By installing it by default, `collectstatic` will find this application and copy
these static files and add them in the manifest.

Note this application will only be used if `SHOW_DEBUG_TOOLBAR=True`, which is
`False` by default.
@humitos humitos requested a review from agjohnson November 22, 2022 16:57
@humitos humitos requested a review from a team as a code owner November 22, 2022 16:57
@humitos humitos requested a review from stsewd November 22, 2022 16:57
Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with exactly what debug-toolbar adds, but is there any concerns of parts of debug-toolbar leaking out to the prod application? I'll defer to you all here, but I'm guessing the added views/URLs are the largest concern, which we'd avoid in prod already.

It does seems a little odd to need this on prod, but the only other solution would be doing a collectstatic for prod and a separate collectstatic just for web-extra?

@humitos
Copy link
Member Author

humitos commented Nov 22, 2022

I'm not familiar with exactly what debug-toolbar adds, but is there any concerns of parts of debug-toolbar leaking out to the prod application? I'll defer to you all here, but I'm guessing the added views/URLs are the largest concern, which we'd avoid in prod already.

I think installing an app without adding middlewares or URLs is safe. Isn't it?

It does seems a little odd to need this on prod, but the only other solution would be doing a collectstatic for prod and a separate collectstatic just for web-extra?

I thought about this, but... I suppose this could break since web-extra may not have the same applications installed than regular webs and then those static files won't be available for web.

@agjohnson
Copy link
Contributor

I think installing an app without adding middlewares or URLs is safe. Isn't it?

This is a good question. Looking at the application initialization, it does have side effects:

https://github.com/jazzband/django-debug-toolbar/blob/main/debug_toolbar/apps.py#L17

This seems to start initialization of the "panels". I'm not familiar enough with debug-toolbar internals to answer if this has zero side-effects without the middleware.

@agjohnson
Copy link
Contributor

I'm guessing there won't be anything we can do that makes me feel 100% okay with installing debug applications in prod. If anyone else wants to overrule me here, I'll defer to anyone with more background on debug-toolbar.

@humitos
Copy link
Member Author

humitos commented Nov 23, 2022

Another option could be to do something like:

# settings.py

if "collectstatic" in cmd or RTD_SHOW_DEBUG_TOOLBAR :
  app.append("debug_toolbar")

That way we will install it only when running collectstatic or when we force it from the admin instance. Would this be an acceptable option? 🤔

@agjohnson
Copy link
Contributor

Hah nice! If it's possible to do that, that does seem fine. I think as long as the prod web process doesn't evaluate debug toolbar, we're safe 👍

@benjaoming
Copy link
Contributor

That way we will install it only when running collectstatic or when we force it from the admin instance. Would this be an acceptable option? thinking

In which cases are we running collectstatic + want DjDT assets + don't have DjDT enabled? Is it possible to do this only when RTD_SHOW_DEBUG_TOOLBAR is configured?

What I mean:

if RTD_SHOW_DEBUG_TOOLBAR :
    app.append("debug_toolbar")

@humitos
Copy link
Member Author

humitos commented Nov 24, 2022

In which cases are we running collectstatic + want DjDT assets + don't have DjDT enabled? Is it possible to do this only when RTD_SHOW_DEBUG_TOOLBAR is configured?

We run collectstatic from the web application which does not have debug_toolbar installed. That means that assets are not copied. Then we run an instance from web-extra that has the debug_toolbar installed. As the assets are shared between all the instances, the assets for debug_toolbar are not in S3 at this point.

So, we need to have debug_toolbar installed at the moment we are running collectstatic.

Use a "staticfiles finder" to find static files from an app that's not installed
in Django when running `collectstatic`.

This method is less intrusive and safe to run on production since it does not
execute `debug_toolbar` code on `web` instances.
@humitos humitos requested a review from agjohnson November 24, 2022 17:41
@humitos
Copy link
Member Author

humitos commented Nov 24, 2022

I changed the pattern here for a safer one.

I created a "static files finder" to always copy the static files from debug_toolbar, even if it's not on INSTALLED_APPS. This way, no matter from where we execute the collectstatic command, it will always copy these files --which is exactly what we want and it's safe to do 👍🏼

I tested it locally, and I ended up with the debug_toolbar/{css,js} folders in the MinIO, 💯

@benjaoming
Copy link
Contributor

This sounds like a great solution 👍

Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooo, this is a really nice solution 💯

This seems much safer 👍

@humitos humitos enabled auto-merge (squash) November 28, 2022 18:43
@humitos humitos disabled auto-merge November 29, 2022 10:11
@humitos
Copy link
Member Author

humitos commented Nov 29, 2022

The docs-dev is failing, but I haven't change anything related to that, so 🤷🏼 . I'm merging this PR because we need it for today's deploy. We can come back later and fix the docs issue.

@humitos humitos merged commit 64fffd7 into main Nov 29, 2022
@humitos humitos deleted the humitos/debug-toolbar branch November 29, 2022 10:14
@humitos humitos added the PR: hotfix Pull request applied as hotfix to release label Nov 29, 2022
humitos added a commit that referenced this pull request Nov 29, 2022
* Admin: install `debug_toolbar`

This application needs to be installed if we want to enable it later in the
`web-extra` instance. Otherwise, it fails due the static files are not in the
manifest.

By installing it by default, `collectstatic` will find this application and copy
these static files and add them in the manifest.

Note this application will only be used if `SHOW_DEBUG_TOOLBAR=True`, which is
`False` by default.

* Copy static files from `debug_toolbar` even when it's not installed

Use a "staticfiles finder" to find static files from an app that's not installed
in Django when running `collectstatic`.

This method is less intrusive and safe to run on production since it does not
execute `debug_toolbar` code on `web` instances.

* pre-commit linting

* Linting issue fixed
humitos added a commit that referenced this pull request Nov 29, 2022
* Admin: install `debug_toolbar`

This application needs to be installed if we want to enable it later in the
`web-extra` instance. Otherwise, it fails due the static files are not in the
manifest.

By installing it by default, `collectstatic` will find this application and copy
these static files and add them in the manifest.

Note this application will only be used if `SHOW_DEBUG_TOOLBAR=True`, which is
`False` by default.

* Copy static files from `debug_toolbar` even when it's not installed

Use a "staticfiles finder" to find static files from an app that's not installed
in Django when running `collectstatic`.

This method is less intrusive and safe to run on production since it does not
execute `debug_toolbar` code on `web` instances.

* pre-commit linting

* Linting issue fixed
@benjaoming
Copy link
Contributor

benjaoming commented Dec 8, 2022

As noted in #9791:

I was going through our PRs since #9734 and this is one of the few PRs that doesn't change our docs.

It didn't, however, skip the documentation build:

https://readthedocs.org/projects/dev/builds/18765036/

But it did contain the feature:

if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- docs/;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: hotfix Pull request applied as hotfix to release
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants