-
Notifications
You must be signed in to change notification settings - Fork 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
'djdt' is not a registered namespace #1405
Comments
How does |
Hi Tim, |
Hi there, I have recently started working on a large project and have tried adding django-debug-toolbar. The setup works perfectly, however when any unit tests that make use of the django test client to make requests to views run, I receive the I read that when running unit tests django explicitly sets DEBUG to false (See here). I have begun debugging the issue and it seems the following happens when the unit tests are run:
Is the use of the django test client a known issue with debug toolbar? As I mentioned above the project is quite large and there may be something else causing the issue. In the meantime I am going to provide a environment variable specifically for the setup of the debug-toolbar. |
Here's the way I do it these days. I have a DEBUG and a TESTING setting: Then, I initialize Now Django (and other packages) can change DEBUG as much as they want, debug toolbar is either activated completely or not at all. |
Awesome! Thanks @matthiask |
@matthiask Do you think it's possible and worth us implementing a check that would prevent the toolbar from being instrumented if it's for a test run? |
@tim-schilling I doubt there is an easy way to achieve this. We'd have to find solutions for pytest, unittest etc. The |
Same error. Cannot get it to run. |
Solved - Accidentally uploaded the urls.py of the project to the app directory of the server |
Is this resolved? |
I discovered that there is an issue going on with debug_toolbar app at the moment. So its better to remove that code for now. Here is the resource: django-commons/django-debug-toolbar#1405
Hi,
Can you please include your urls.py file?
…On Thu, Jul 8, 2021, 12:21 AM Dip Dhanesha ***@***.***> wrote:
Is this resolved?
I am getting this error as well. I followed installation steps mention
here:
https://django-debug-toolbar.readthedocs.io/en/latest/installation.html
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1405 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJYZP7FZI6I3VUTUPUIAM3TWUYVLANCNFSM4T55GDLA>
.
|
@ddhanesha Looking at your code base, you need to inject the toolbar into your |
Hello, I have the exact same situation as OP and I have the same long error response. The only workaround I see is to use the flag |
@martinberoiz have you setup your project to add the toolbar to |
@tim-schilling yes, that is correct. This is how I configured: # base.py
if DEBUG:
MIDDLEWARE.insert(0, 'debug_toolbar.middleware.DebugToolbarMiddleware')
DEBUG_TOOLBAR_CONFIG = {"SHOW_TOOLBAR_CALLBACK": lambda request: DEBUG}
INSTALLED_APPS += ('debug_toolbar',) # urls.py
if settings.DEBUG:
urlpatterns += (path('__debug__/', include('debug_toolbar.urls')),) I just noticed that I didn't set |
@martinberoiz what's going on is what is explained here #1405 (comment) DEBUG is actually True when settings load, so MIDDLEWARE and INSTALLED_APPS are setup with the toolbar, then the test runner flips debug to false. However, MIDDLEWARE and INSTALLED_APPS are already populated with the debug settings. The solution is to use Matthias' approach as defined here: #1405 (comment) See https://github.com/matthiask/workbench/blob/5e3663cb7c28cec707cfe746e9072e4fa6778f30/workbench/settings.py#L16-L17 for an example of how he sets them. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Hi @tim-schilling and @matthiask This is how I am thinking about it Have a section called Then add the following: Additional Note To debug this issue use the following:
|
I definitely use I'm not sure if setting
Maybe we could add a system check (here https://github.com/jazzband/django-debug-toolbar/blob/main/debug_toolbar/apps.py ) for |
The goal of this issue is to solve how a user configures DDT in the context of runserver and running tests. When tests are run, django does some weird things with DEBUG that results in the toolbar being installed, but DEBUG being set to False. When the tests run, there are errors that seem impossible. |
Thanks @tim-schilling -- I reacted too quickly without checking the full thread. |
I think I'd prefer to see these changes included in the original setup @VeldaKiara. I think the additional note could work, but it would effectively need to redefine how the toolbar would be enabled using the |
I did not move it there on the assumption that it does not happen to everyone that's the perspective I had. I used the djdt on one of my django apps and I did not get the issue. I like the idea of putting it on the installation but do I add it as an optional note, with a statement of if the above condition occurs then adjust to these settings? |
* updated the change to the changes.rst file * solution to djdt registered namespace,update docs, system checks and tests * removing test in the if statements * Add basic test to example app and example_test to make commands. * Update check for toolbar and tests. * update check using with, combine the four tests to one, update default config * update installation files and remove patch from namespace check * Clean-up the changelog * Add docs for the IS_RUNNING_TESTS setting Co-authored-by: Matthias Kestenholz <mk@feinheit.ch> * Change the code for the toolbar testing error to E001 * Reduce number of .settings calls and document config update. --------- Co-authored-by: Tim Schilling <schillingt@better-simple.com> Co-authored-by: Matthias Kestenholz <mk@feinheit.ch>
Closed in #1889 |
I got this error when I run django unittest, I have tried all the answers I could find, seems not working.
Here are my settings:
Project url file:
If I turn off the debug to False manually, then the error is gone, if I just run manage.py test with all those settings above or either same as the official doc , then I get the this error.
Is there any method to avoid this error? Doesn't the debug suppose to be False when running a test?
The text was updated successfully, but these errors were encountered: