ndarville / pony-forum

A modern alternative to ancient forum CMSes like vBulletin and PHPBB in Python on Django. (Alpha stage.) (NB: dotCloud have since removed their free Sandbox tier.)
http://pony-forum.com
26 stars 7 forks source link

Settings environment variable problem #103

Closed ndarville closed 11 years ago

ndarville commented 11 years ago

Happens with both Travis and dotCloud. The really weird thing is how arbitrary the build that starts breaking is on Travis: https://travis-ci.org/ndarville/pony-forum/builds. The only difference between the successful commit and the failed build are some alterations to a Markdown file(?!). The mind boggles.

Travis

Traceback (most recent call last):
  File "_postinstall/mkadmin.py", line 11, in <module>
    from django.contrib.auth.models import User
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 5, in <module>
    from django.db import models
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'ponyforum.settings' (Is it on sys.path?): No module named ponyforum.settings
$ python _postinstall/definesite.py
Traceback (most recent call last):
  File "_postinstall/definesite.py", line 8, in <module>
    from django.contrib.sites.models import Site
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/contrib/sites/models.py", line 1, in <module>
    from django.db import models
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'ponyforum.settings' (Is it on sys.path?): No module named ponyforum.settings
$ python _postinstall/mkplaceholders.py
Traceback (most recent call last):
  File "_postinstall/mkplaceholders.py", line 17, in <module>
    from django.contrib.auth.models import User
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 5, in <module>
    from django.db import models
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'ponyforum.settings' (Is it on sys.path?): No module named ponyforum.settings

dotCloud

 Traceback (most recent call last):
   File "_postinstall/definesite.py", line 8, in <module>
     from django.contrib.sites.models import Site
   File "/opt/ve/2.7/local/lib/python2.7/site-packages/django/contrib/sites/models.py", line 1, in <module>
     from django.db import models
   File "/opt/ve/2.7/local/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
     if DEFAULT_DB_ALIAS not in settings.DATABASES:
   File "/opt/ve/2.7/local/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
     self._setup()
   File "/opt/ve/2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
     raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
 ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
 deployment aborted due to unexpected command result: "chmod +x postinstall ; ./postinstall" failed with return code 1
 Installation failed for service (www) instance #0
21:27:13.316375: --> Deployment of application (ponyforum) failed with 1 installation error(s)
ndarville commented 11 years ago

Just tried deploying the earlier to dotCloud starting from the latest commit. For some reason, this commit keeps deploying successfully on dotCloud; all the later versions (tried beforehand) fail.

02dcdf855b366a4121d4bb7fbfd282632f65a0e9

And yet, it obviously failed on Travis.

ndarville commented 11 years ago

In other words, the problem arose earlier than reported, but Travis and dotCloud didn’t detect it the first time.

ndarville commented 11 years ago

The builds from my fonts branch are also failing now, even though they are from a branch of master that exists much, much earlier than the original failing builds.

The build also managed to deploy to dotCloud just fine.

  1. My fonts branch, which is much older than the failing builds, also fails on Travis now
  2. It deploys without a hitch to dotCloud

Consistent irregularity.

ndarville commented 11 years ago

Moving the env var declaration from an export script to env did not fix it.

ndarville commented 11 years ago

The problem does not appear on dotCloud in the fonts branch. It does on Travis, though.

ndarville commented 11 years ago

The above commit fixed the problems on dotCloud. Now they only seem to remain with Travis which can’t import the settings through its environment for some reason.

Two more fixes: 10d3554b85b3ebe116f4d94a85084d0412cdaa0a and 45825fef70ac88d3f0f60f92b5093d110e7c6c84.

ndarville commented 11 years ago

The latest Travis error after the recent fixes:

$ python _postinstall/mkadmin.py
Traceback (most recent call last):
  File "_postinstall/mkadmin.py", line 11, in <module>
    from django.contrib.auth.models import User
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 5, in <module>
    from django.db import models
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'ponyforum.settings' (Is it on sys.path?): No module named ponyforum.settings

The command "python _postinstall/mkadmin.py" exited with 1.
$ python _postinstall/definesite.py
Traceback (most recent call last):
  File "_postinstall/definesite.py", line 23, in <module>
    from django.contrib.sites.models import Site
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/contrib/sites/models.py", line 1, in <module>
    from django.db import models
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'ponyforum.settings' (Is it on sys.path?): No module named ponyforum.settings

The command "python _postinstall/definesite.py" exited with 1.
$ python _postinstall/mkplaceholders.py
Traceback (most recent call last):
  File "_postinstall/mkplaceholders.py", line 17, in <module>
    from django.contrib.auth.models import User
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 5, in <module>
    from django.db import models
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'ponyforum.settings' (Is it on sys.path?): No module named ponyforum.settings
ndarville commented 11 years ago

Links:

  1. http://stackoverflow.com/questions/12987648/importerror-could-not-import-settings
  2. http://stackoverflow.com/questions/11573264/django-importerror-for-models-py/11586261#11586261
  3. http://stackoverflow.com/questions/6772937/importerror-no-module-named-models
  4. http://stackoverflow.com/questions/11573264/django-importerror-for-models-py
  5. http://stackoverflow.com/questions/2575859/importerror-and-django-driving-me-crazy/2575926#2575926
  6. http://stackoverflow.com/questions/9353092/could-not-import-settings-myproject-settings-is-it-on-sys-path-no-module-n
ndarville commented 11 years ago