0

After upgrading from django 1.9.6 to 1.11.11, running crossbar 17.10.1 with the following guest worker configuration fails due to not finding the DJANGO_SETTINGS_MODULE ("simpl_calc_model.settings").

{
    "type": "guest",
    "executable": "django-admin",
    "arguments": ["run_guest"],
    "options": {
        "workdir": "..",
        "env": {
            "vars": {
                "HOSTNAME": "localhost",
                "PORT": "8080"
            }
        }
    }
}

I'm running crossbar against this config from a management command in the project containing the simpl_calc_model directory. I can run the guest worker directly in this project like so:

./manage.py run_guest --settings=simpl_calc_model.settings

How to I ensure django-admin 1.11.11 can find the settings module when called from crossbar via my management command?

The error log looks like:

Traceback (most recent call last):
File " ~/.virtualenvs/simpl-calc-model/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File " ~/.virtualenvs/simpl-calc-model/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File " ~/.virtualenvs/simpl-calc-model/lib/python3.6/site-packages/django/core/management/__init__.py", line 308, in execute
settings.INSTALLED_APPS
File " ~/.virtualenvs/simpl-calc-model/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File " ~/.virtualenvs/simpl-calc-model/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File " ~/.virtualenvs/simpl-calc-model/lib/python3.6/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File " ~/.virtualenvs/simpl-calc-model/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'simpl_calc_model'  
softweave
  • 1,455
  • 2
  • 16
  • 27
  • Where is the `simpl_calc_model` that isn't being found? Is it on the Python path? Try using `manage.py` instead of `django-admin` it takes care of setting the path for you. – Alasdair Mar 23 '18 at 14:23
  • Alasdair I added more information to the question ^^^ – softweave Mar 23 '18 at 14:55
  • So if `manage.py` works, why not use it in your crossbar config instead of `django-admin`? If you use `django-admin`, it looks as if you're going to have to add the directory containing `simpl_calc_model` to the Python path so that it can be imported. – Alasdair Mar 23 '18 at 15:04
  • 1
    Thanks Alasdair! – softweave Mar 23 '18 at 16:26
  • Glad you got it working. It would be better to add your solution as an answer. That way, you can mark it as accepted, and it's clear that you've solved your problem. – Alasdair Mar 23 '18 at 16:27

1 Answers1

0

Fixed problem by implementing Alasdair's suggestion and removing workdir:

{
    "type": "guest",
    "executable": "manage.py",
    "arguments": ["run_guest"],
    "options": {
        "env": {
            "vars": {
                "HOSTNAME": "localhost",
                "PORT": "8080"
            }
        }
    }
}
softweave
  • 1,455
  • 2
  • 16
  • 27