New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix broken error ouput for django.setup() call. #12602
Fix broken error ouput for django.setup() call. #12602
Conversation
5a9adac
to
a90e219
Compare
@timabbott I tested this out in a production environment and it looks to be doing the job. Looking forward to your feedback :) |
zproject/wsgi.py
Outdated
try: | ||
django.setup() # We need to call setup to load applications. | ||
except NameError as e: | ||
logger.error(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put the block that configures the logger here, so it only runs in the exception case?
Also, we should reraise the exception to exit, rather than continuing execution...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also, I think if we use logger.exception
, the full traceback will go in the log, which is probably what we want?)
This looks like a reasonable approach; let's test the improvements I suggested above. |
a90e219
to
2e5f952
Compare
It's common for a broken settings.py file to result in Django not starting, thus never writing to `/var/log/zulip/errors.log`. Such behavior can be discouraging when the server 500s without a traceback to accompany it. To fix this, we simply catch the NameError, if raised, and log the exception appropriately. Closes: zulip#7032
2e5f952
to
1847dcf
Compare
@timabbott FYI :) I moved
|
Merged as 3c1982e, after tweaking the comments for clarity and making it catch all exceptions, not just NameError (there's other syntax issues one can create in Thanks @whoodes! This will result in a nontrivial reduction in folks being confused when they make mistakes setting up a Zulip production system. |
When settings.py is broken, Django doesn't start. When Django doesn't
start, relevant data is never written to our errors.log file.
This isn't desirable, so we instead catch any
NameError
s that mayarise and log them appropriately.
Closes: #7032
Tested by:
'Foo': bar
withinDEFAULT_SETTINGS
insettings.py
supervisorctl restart all
internal server error
2019-06-19 20:29:25,535 ERROR zproject.wsgi name 'bar' is not defined
was invar/log/zulip/errors.log
.