Skip to content

Conversation

mbertheau
Copy link

decorator initially contains the list of decorators that show_urls
should look for. However, it was overwritten with the the formatted
decorators further down the loop body. As a consequence, starting from
the second loop iteration no decorators were found anymore.

Now, the variable decorators holds the formatted decorator information.

`decorator` initially contains the list of decorators that show_urls
should look for. However, it was overwritten with the the formatted
decorators further down the loop body. As a consequence, starting from
the second loop iteration no decorators were found anymore.

Now, the variable `decorators` holds the formatted decorator information.
@takis
Copy link

takis commented Jun 25, 2022

I was just about to clean up a patch for this bug, when I noticed your pull request. What are the odds, working on this on the same day 😄

This bug seems to have been introduced in commit 702f798.

This was my patch, in which I forgot to handle the JSON-output format...

diff --git a/django_extensions/management/commands/show_urls.py b/django_extensions/management/commands/show_urls.py
index cddca120..59b6295a 100644
--- a/django_extensions/management/commands/show_urls.py
+++ b/django_extensions/management/commands/show_urls.py
@@ -79,9 +79,9 @@ class Command(BaseCommand):
         else:
             self.LANGUAGES = getattr(settings, 'LANGUAGES', ((None, None), ))
 
-        decorator = options['decorator']
-        if not decorator:
-            decorator = ['login_required']
+        decorator_option = options['decorator']
+        if not decorator_option:
+            decorator_option = ['login_required']
 
         format_style = options['format_style']
         if format_style not in FMTR:
@@ -119,7 +119,7 @@ class Command(BaseCommand):
             else:
                 func_globals = {}
 
-            decorators = [d for d in decorator if d in func_globals]
+            decorators = [d for d in decorator_option if d in func_globals]
 
             if isinstance(func, functools.partial):
                 func = func.func

702f798

Copy link

@takis takis left a comment

Choose a reason for hiding this comment

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

I've read and tried the patch and I can confirm the bug exists and that the patch fixes the problem.

@mbertheau
Copy link
Author

mbertheau commented Jun 25, 2022

Just as an fyi: with this change many people will see the login_required decorator turn up in their show_urls output where is wasn't there before, since a) default Django URLs have this decorator and it's a common decorator for custom routes, and b) is the default decorator looked for by the code when no --decorator option was given.

It might be a good idea to remove this default, because other than specifying a dummy decorator to look for, there's no way to disable it.

@takis
Copy link

takis commented Nov 30, 2022

Hi @mbertheau ,

I've had another look at this, but it seems although your patch fixes the bug introduced in commit 702f798, -unless I'm mistaken- it does not seem to fix the behavior.

I've created a new issue #1773 to illustrate its behavior before and after the patch.

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