#34020: django core management error
--------------------------------------------+------------------------
               Reporter:  brian-methodical  |          Owner:  nobody
                   Type:  Uncategorized     |         Status:  new
              Component:  Uncategorized     |        Version:  4.0
               Severity:  Normal            |       Keywords:
           Triage Stage:  Unreviewed        |      Has patch:  0
    Needs documentation:  0                 |    Needs tests:  0
Patch needs improvement:  0                 |  Easy pickings:  0
                  UI/UX:  0                 |
--------------------------------------------+------------------------
 When running custom admin management command getting unexpected error "

 'NoneType' object has no attribute 'endswith'


 Here is the stack-trace:


 ```

 {{{
 Traceback (most recent call last):
   File "/Users/brianray/GitHub/methodical-feature-
 space/fserve/./manage.py", line 21, in <module>
     main()
   File "/Users/brianray/GitHub/methodical-feature-
 space/fserve/./manage.py", line 17, in main
     execute_from_command_line(sys.argv)
   File "/opt/anaconda3/lib/python3.9/site-
 packages/django/core/management/__init__.py", line 446, in
 execute_from_command_line
     utility.execute()
   File "/opt/anaconda3/lib/python3.9/site-
 packages/django/core/management/__init__.py", line 440, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/opt/anaconda3/lib/python3.9/site-
 packages/django/core/management/base.py", line 414, in run_from_argv
     self.execute(*args, **cmd_options)
   File "/opt/anaconda3/lib/python3.9/site-
 packages/django/core/management/base.py", line 460, in execute
     output = self.handle(*args, **options)
   File "/Users/brianray/GitHub/methodical-feature-
 space/fserve/ftasks/management/commands/dumpurls.py", line 15, in handle
     self.stdout.write(pprint.pprint(urls))
   File "/opt/anaconda3/lib/python3.9/site-
 packages/django/core/management/base.py", line 169, in write
     if ending and not msg.endswith(ending):
 AttributeError: 'NoneType' object has no attribute 'endswith'

 }}}

 ```

 To reproduce take this code:

 ```

 {{{

 from django.core.management.base import BaseCommand
 from django.urls import get_resolver
 import pprint

 class Command(BaseCommand):
     help = 'dumps all the endpoint urls'


     def handle(self, *args, **options):
         urls = {pat.name: str(pat.pattern._route) for pat in
 get_resolver().url_patterns
                 if getattr(pat, "name", None)}

         self.stdout.write(self.style.SUCCESS('Here are the urls: \n\n'))

         self.stdout.write(pprint.pprint(urls))
         self.stdout.write("\n")
         return True

 }}}

 ```

 put into {BASE}/{module}/management/commands ...

 Django==4.0.5

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34020>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070183488be1a6-c6fd5b0d-0313-4e92-acb2-5c75c0c4ff62-000000%40eu-central-1.amazonses.com.

Reply via email to