#34020 closed Uncategorized (invalid)
django core management error
| Reported by: | brian-methodical | Owned by: | nobody |
|---|---|---|---|
| Component: | Uncategorized | Version: | 4.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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
Note:
See TracTickets
for help on using tickets.
Traceback clearly points at the
self.stdout.write(pprint.pprint(urls))call being the origin of the issue.pprint.pprintreturnsNone,self.stdout.writeexpects a string, and the error messages clears state'NoneType' object has no attribute 'endswith'.Please avoid using this ticket tracker unless you have confirmed this is an issue with Django through TicketClosingReasons/UseSupportChannels.