mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Apply patch from Chris Lamb <lamby@debian.org> with minor revision.
Validate models before allowing connections via gunicorn_django This prevents issues where the site is accepting connections but not all of the models have loaded yet. If your model importing has side effects (monkey-patching, etc) this can results in errors about missing attributes or features simply because the code that enables those features as not been run yet. This issue does not affect the "run_gunicorn" management command as that performs it's own model validation before allowing connections, so we are simply making this consistent here. Signed-off-by: Chris Lamb <lamby@debian.org>
This commit is contained in:
parent
894e2d2526
commit
4b2c04317c
@ -69,12 +69,31 @@ class DjangoApplication(Application):
|
|||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
""" Validate models. This also ensures that all models are
|
||||||
|
imported in case of import-time side effects."""
|
||||||
|
from django.core.management.base import CommandError
|
||||||
|
from django.core.management.validation import get_validation_errors
|
||||||
|
try:
|
||||||
|
from cStringIO import StringIO
|
||||||
|
except ImportError:
|
||||||
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
s = StringIO()
|
||||||
|
if get_validation_errors(s):
|
||||||
|
s.seek(0)
|
||||||
|
error = s.read()
|
||||||
|
sys.stderr.write("One or more models did not validate:\n%s" % error)
|
||||||
|
sys.stderr.flush()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
from django.conf import ENVIRONMENT_VARIABLE
|
from django.conf import ENVIRONMENT_VARIABLE
|
||||||
from django.core.handlers.wsgi import WSGIHandler
|
from django.core.handlers.wsgi import WSGIHandler
|
||||||
os.environ[ENVIRONMENT_VARIABLE] = self.settings_modname
|
os.environ[ENVIRONMENT_VARIABLE] = self.settings_modname
|
||||||
# setup environ
|
# setup environ
|
||||||
self.setup_environ()
|
self.setup_environ()
|
||||||
|
self.validate()
|
||||||
return WSGIHandler()
|
return WSGIHandler()
|
||||||
|
|
||||||
class DjangoApplicationCommand(Application):
|
class DjangoApplicationCommand(Application):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user