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 Upgrade] [ENG-3947] Fix django debug toolbar and profiling tools for Django 3 #9987

Conversation

Johnetordoff
Copy link
Contributor

@Johnetordoff Johnetordoff commented Jul 21, 2022

Purpose

The DJDTB is breaking when updating to Django 3 and though the bugs aren't particularly hard to fix this PR removes the DJDTB and other local profiling tools which could produce other issues in the future.

https://www.notion.so/cos/8-Django-Debug-toolbar-namespace-problem-0142b5d4dced4bbd9ce8d311d6935e6a

Changes

  • Moves local requirements to local.txt
  • isolates CI only requirments to dev.txt

QA Notes

Please make verification statements inspired by your code and what your code touches.

  • Verify
  • Verify

What are the areas of risk?

Any concerns/considerations/questions that development raised?

Documentation

Side Effects

Ticket

@Johnetordoff Johnetordoff force-pushed the remove-django-debug-toolbar branch from 1c255aa to a98cff1 Compare July 21, 2022 14:59
@cslzchen cslzchen force-pushed the feature/django_upgrade branch from 65b0360 to 250b832 Compare July 27, 2022 19:20
@Johnetordoff Johnetordoff mentioned this pull request Aug 4, 2022
14 tasks
@Johnetordoff Johnetordoff force-pushed the remove-django-debug-toolbar branch from 4e84337 to 7c845bb Compare August 4, 2022 20:30
@Johnetordoff Johnetordoff marked this pull request as ready for review August 4, 2022 20:49
api/base/urls.py Outdated Show resolved Hide resolved
api/base/urls.py Outdated Show resolved Hide resolved
requirements/dev.txt Outdated Show resolved Hide resolved
@Johnetordoff Johnetordoff force-pushed the remove-django-debug-toolbar branch 8 times, most recently from 8907783 to 0f33c1f Compare August 9, 2022 15:55
Copy link
Collaborator

@cslzchen cslzchen left a comment

Choose a reason for hiding this comment

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

As discussed in flow, people may still use these tools. Let's keep it as for "pre-upgrade" fixes. We can remove these after the upgrade if it take too much effort to fix.

@cslzchen cslzchen changed the title Remove django debug toolbar and profiling tools for Django 3 [Django Upgrade] [Pending] Remove django debug toolbar and profiling tools for Django 3 Aug 10, 2022
@Johnetordoff Johnetordoff force-pushed the remove-django-debug-toolbar branch 6 times, most recently from 868882d to b15db2e Compare August 10, 2022 19:43
@cslzchen cslzchen self-requested a review August 11, 2022 04:01
@cslzchen cslzchen changed the title [Django Upgrade] [Pending] Remove django debug toolbar and profiling tools for Django 3 [Django Upgrade] [ENG-3947] Remove django debug toolbar and profiling tools for Django 3 Aug 11, 2022
echo=True
)
install_from_txt(ctx, os.path.join(HERE, 'requirements', 'dev.txt'))
elif base: # then base requirements
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to an elif because these .txt all contain a -r ../requirements.txt so they incorporate those reqs anyway.

@Johnetordoff Johnetordoff force-pushed the remove-django-debug-toolbar branch from b15db2e to aff3e8a Compare August 11, 2022 12:37
Copy link
Collaborator

@cslzchen cslzchen left a comment

Choose a reason for hiding this comment

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

Looks good as discussed. I will make a few updates and push back before merge. See comments for details.

@@ -126,6 +126,7 @@ api/static/vendor
# Local settings files
local.py
local.json
requirements/debug.txt
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would just have debug.txt instead of having a -dist version, which I will update and push back.

@@ -0,0 +1,17 @@
-r ../requirements.txt

# Requirements that are used locally only for a good developer experience
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to mention the difference, missing two removed packages. I am OK removing django-sslserver but why removing django-silk? I will add it back in my update.

django-sslserver==0.19
django-silk==2.0.0

@@ -19,7 +19,7 @@


try:
from tasks import local # noqa
from tasks import local as local_dist # noqa
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 I see. We import here just to check file existence without using it. That's why I am not seeing any usage diff.

Comment on lines +48 to +52
def install_from_txt(ctx, req_path):
ctx.run(
pip_install(req_path),
echo=True
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 for reducing dup code, I will add docstr

Comment on lines +274 to +275
if debug: # then local debugging tools
install_from_txt(ctx, os.path.join(HERE, 'requirements', 'debug.txt'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering about the orders of dev, base and debug. debug is another level after dev thus needs dev. I think updating the -r option in debug.txt to point dev.txt will solve this.

Comment on lines 237 to 250

if DEBUG:
INSTALLED_APPS += ('debug_toolbar', 'nplusone.ext.django',)
MIDDLEWARE += ('debug_toolbar.middleware.DebugToolbarMiddleware', 'nplusone.ext.django.NPlusOneMiddleware',)
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': lambda _: True,
'DISABLE_PANELS': {
'debug_toolbar.panels.templates.TemplatesPanel',
'debug_toolbar.panels.redirects.RedirectsPanel'
}
}

# If set to True, automated tests with extra queries will fail.
NPLUSONE_RAISE = False
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe our plan is to keep these.

Comment on lines 40 to 46
if DEBUG:
import debug_toolbar

urlpatterns += [
url(r'^__debug__/', include(debug_toolbar.urls)),
]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto

Comment on lines 310 to 312
# If set to True, automated tests with extra queries will fail.
NPLUSONE_RAISE = False

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto

Comment on lines 14 to 31
if DEBUG:
INSTALLED_APPS += ('debug_toolbar', 'nplusone.ext.django',)
MIDDLEWARE += (
'debug_toolbar.middleware.DebugToolbarMiddleware',
'nplusone.ext.django.NPlusOneMiddleware',
)
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': lambda _: True,
}
ALLOWED_HOSTS.append('localhost')

# django-silk
INSTALLED_APPS += ('silk',)
MIDDLEWARE += (
'django.contrib.sessions.middleware.SessionMiddleware',
'silk.middleware.SilkyMiddleware',
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto

api/base/urls.py Outdated
Comment on lines 83 to 96
# Add django-silk URLs if it's in INSTALLED_APPS
if 'silk' in settings.INSTALLED_APPS:
urlpatterns += [
url(r'^silk/', include('silk.urls', namespace='silk')),
]

if settings.DEBUG:
import debug_toolbar

urlpatterns += [
url(r'^__debug__/', include(debug_toolbar.urls)),
]


Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto

@Johnetordoff Johnetordoff changed the title [Django Upgrade] [ENG-3947] Remove django debug toolbar and profiling tools for Django 3 [Django Upgrade] [ENG-3947] Fix django debug toolbar and profiling tools for Django 3 Aug 16, 2022
@Johnetordoff Johnetordoff force-pushed the remove-django-debug-toolbar branch from 415be8a to a222153 Compare August 16, 2022 17:27
@cslzchen
Copy link
Collaborator

cslzchen commented Aug 16, 2022

@Johnetordoff the test failure tells us either that our GitHub Action tests have settings.DEBUG set to true or that somehow requirements cannot be conditionally required/chosen by using an if statement

Update: confirmed local-travis.py has DEBUG_MODE = True.

@Johnetordoff Johnetordoff force-pushed the remove-django-debug-toolbar branch from e17a48d to b0c3e27 Compare August 16, 2022 19:38
@cslzchen
Copy link
Collaborator

A minor concern that I forgot to mention, though I doubt it is actually an issue: DEBUG might have been turned on for a reason for CI (instead of just a copy from local settings). We shouldn't just turn it off to pass CI tests.

@cslzchen
Copy link
Collaborator

cslzchen commented Sep 1, 2022

PR closed since #10049 fixes the issue with a few troubling dev/local requirements.

@cslzchen cslzchen closed this Sep 1, 2022
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

Successfully merging this pull request may close these issues.

2 participants