From a8e8b30e47ada1121c950d06809002ebf75385cb Mon Sep 17 00:00:00 2001 From: Hobson Lane Date: Tue, 22 Apr 2014 16:33:41 -0700 Subject: [PATCH] Fix code.djangoproject.com/ticket/20185 This change favors `python2` over `python3` by reversing the try/except order. Untested in `python3`, as most Django packages are not yet `python3`-compatible. Works in `python2`, `Django 1.5.4`, `gunicorn 18.0`. When running `gunicorn` in python 2, if a django model doesn't validate, the `gunicorn` will fail to display informative error messages about your model and instead complain about `str`/`unicode`: Django was falsely accused of [this bug](https://code.djangoproject.com/ticket/20185) --- gunicorn/app/django_wsgi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gunicorn/app/django_wsgi.py b/gunicorn/app/django_wsgi.py index f1c566a6..b689ae7f 100644 --- a/gunicorn/app/django_wsgi.py +++ b/gunicorn/app/django_wsgi.py @@ -10,10 +10,10 @@ import re import sys import time try: + from StringIO import StringIO +except: from io import StringIO from imp import reload -except ImportError: - from StringIO import StringIO from django.conf import settings