Prevent check from erroring when ROOT_URLCONF is not defined - #2342
Conversation
matthiask
left a comment
There was a problem hiding this comment.
I wonder if we shouldn't do the same thing Django's own checks do and check getattr(settings, "ROOT_URLCONF", None) first. Catching any AttributeError feels a bit too broad to be honest, but if there are additional reasons for that or if my suggestion doesn't make sense I'm good with the change as it is right now.
|
@matthiask I had thought about that, the reason I went more broad is because there are uses where a Django app might not use
I wasn't sure if there was anything in Django explicitly requiring that Alternatively, we could check that |
|
Could do something like this, but it seems a bit messy try:
get_resolver()
except AttributeError:
toolbar_urls_installed = False
else:
try:
# Check if the toolbar's urls are installed
reverse(f"{APP_NAME}:render_panel")
toolbar_urls_installed = True
except NoReverseMatch:
toolbar_urls_installed = False |
|
You're raising good points. That said, I have never encountered a Django project until now where So, long story short: I think I lean towards the simple solution of skipping the check if (Context: I'm definitely one of the people messing around with |
|
I agree with you. If someone is messing around with I'll push up new changes. |
c1bd8ab to
2d91224
Compare
2d91224 to
e9381e3
Compare
|
Thank you! |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Description
The check
debug_toolbar_installed_when_running_tests_checkchecks if the toolbar's URLs are installed by callingreverse. This can cause issues whenROOT_URLCONFis not defined. In this case,reversewill throw anAttributeError. The check should ignore this error, since if there is noROOT_URLCONFthen it meanstoolbar_urls_installedshould be false.This comes into play when you're using separate settings files for things like management commands, where it's not necessary to define a
ROOT_URLCONF.For reference, the exception in Django gets raised from this line.
Checklist:
docs/changes.rst.AI/LLM Usage