mod_wsgi
mod_wsgi copied to clipboard
Added missing str() call on pathlib object
Fixes the following traceback
Traceback (most recent call last):
File "/opt/app-root/src/manage.py", line 22, in <module>
main()
File "/opt/app-root/src/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/opt/app-root/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/opt/app-root/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/app-root/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/app-root/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/opt/app-root/lib/python3.9/site-packages/mod_wsgi/server/management/commands/runmodwsgi.py", line 134, in handle
options = mod_wsgi.server._cmd_setup_server(
File "/opt/app-root/lib/python3.9/site-packages/mod_wsgi/server/__init__.py", line 3613, in _cmd_setup_server
generate_apache_config(options)
File "/opt/app-root/lib/python3.9/site-packages/mod_wsgi/server/__init__.py", line 1086, in generate_apache_config
if target.endswith('/') and path != '/':
AttributeError: 'PosixPath' object has no attribute 'endswith'
Are you using Django management command wrapper? If yes, what version of Django? What command line arguments are you using?
I can't see how that code you are changing is a problem in itself. The only way can theorise you might get that error is the Django management command wrapper was being used and it was sourcing a path from Django settings in some way that it doesn't get a string. In this case it is the Django management command wrapper that would need to change in that it needs to ensure a string is passed.
Yes I was starting the server via "python manage.py runmodwsgi --log-to-terminal" in a Docker container. Django version is 3.1. I'll do some more digging to see if my settings are pulling in a pathlib object somewhere.
So after some checking my settings.py is using pathlib objects. I changed the patch to be to runmodwsgi.py as you suggested. I think I got everywhere that is referencing a file path pulled in from settings.py.
Is this because you are choosing to use pathlib objects somehow in settings, or Django itself uses them now?
If Django is using them am surprised no one has raised this previously.
Can you provide an example of what your settings file looks like for affected settings?
My settings file is using them, here's a snippet:
BASE_DIR = pathlib.Path(__file__).resolve(strict=True).parent.parent
STATIC_ROOT = BASE_DIR / 'assets'
Basically it's just using them for ease of creating additional paths off the BASE_DIR.