Django 1.11: AttributeError: 'module' object has no attribute 'setup_environ'

122 views
Skip to first unread message

Chi Shiek

unread,
Feb 28, 2019, 2:41:55 PM2/28/19
to Django users
This is related to a bug I raised against app engine while tying to migrate from django 1.5 to 1.11.

The issue is I have an app running on app engine using django 1.5.
Recently I was making a number of major updates to the app and decided to convert to django 1.11 as part of that update.

Everything seemed to work fine on my local dev_appserver, but when I deployed it to app engine, it threw an error similar to this...

ERROR    2019-02-28 19:01:49,710 wsgi.py:263]
Traceback (most recent call last):
  File "/home/cshiek/Programs/google-cloud-sdk-1.9.83/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/home/cshiek/Programs/google-cloud-sdk-1.9.83/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/home/cshiek/Programs/google-cloud-sdk-1.9.83/platform/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
    __import__(cumulative_path)
INFO     2019-02-28 19:01:49,720 module.py:861] default: "GET /Common?action=%5B%22logout%22%5D HTTP/1.1" 500 -
  File "/home/cshiek/Programs/google-cloud-sdk-1.9.83/platform/google_appengine/google/appengine/ext/django/main.py", line 82, in <module>
    management.setup_environ(settings, original_settings_path=settings_path)
AttributeError: 'module' object has no attribute 'setup_environ'


I downloaded the app back to my local development server and built a clean python environment using only the exact modules I needed - and then I saw the same setup_environ error.
The module indicated has the following code which is throwing the error.

try:
  settings = __import__(settings_path)
  management.setup_environ(settings, original_settings_path=settings_path)
except ImportError:
    pass


I changed the code to 
try:
  settings = __import__(settings_path)
  management.setup_environ(settings, original_settings_path=settings_path)
except AttributeError:
  django.setup()
except ImportError:
    pass


And everything works fine.
My problem is that the changed module appears to be inside the google-cloud-sdk and therefore I cannot change it in production.

My app.yaml point to django 1.11

I've searched the net and no one seems to have encountered this problem before...there is a lot about setup_environ, but nothing that addresses this particular issue.

I even raised a ticket against app engine (https://issuetracker.google.com/issues/124539522) but received a reply that it was a django problem.

Question is - has anyone else come across this problem in the app engine environment - and how did you resolve it?

Thanks!
/Chi







Chi Shiek

unread,
Feb 28, 2019, 4:05:40 PM2/28/19
to Django users
Managed to fix it by loading Django as a separate library...
These are the things I had to do...
Used following link to create a libs directory and install django in it (via pip - instructions on the page) - also followed the instructions on this page for creating a appengine_config.py 


Removed django from my app.yaml
libraries:
- name: django
  version: "1.11"

commented out these lines from my main.py
#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
#from django.conf import settings

seems I had this in my app.yaml already
env_variables:
  DJANGO_SETTINGS_MODULE: 'core.settings'

That's about it...oh - also removed the changes I made to...

/home/cshiek/Programs/google-cloud-sdk-1.9.83/platform/google_appengine/google/appengine/ext/django/main.py

Haven't deployed it yet - but at least the dev_appserver is now running properly.

Chi Shiek

unread,
Feb 28, 2019, 4:29:42 PM2/28/19
to Django users
Didn't work in production...same error...suggestions welcome


On Friday, 1 March 2019 06:41:55 UTC+11, Chi Shiek wrote:

Chi Shiek

unread,
Mar 5, 2019, 10:13:20 PM3/5/19
to Django users
Also failing in local dev_appserver. It seemed to work for a very short time (couple of queries) and then it stopped with the same error. 
Gave up and reverting back to 1.4 (which is what app engine seems to recommend - 1.4 or 1.11).
Reply all
Reply to author
Forward
0 new messages