django12factor
django12factor copied to clipboard
wrong sys.exit argument
line 118:
sys.exit("""DEBUG is False but no SECRET_KEY is set in the environment - either it has been hardcoded (bad) or not set at all (bad) - exit()ing for safety reasons""")
Argument should be integer value, so if error message is required, we should raise exception here.
Thanks! So, reading help()
:
>>> help(sys.exit)
Help on built-in function exit in module sys:
exit(...)
exit([status])
Exit the interpreter by raising SystemExit(status).
If the status is omitted or None, it defaults to zero (i.e., success).
If the status is an integer, it will be used as the system exit status.
If it is another kind of object, it will be printed and the system
exit status will be one (i.e., failure).
the usage seems legit as per the last case. Where're you getting
Argument should be integer value
from?
Cheers
Oh, sorry. My problem related to pycharm pydevconsole. pydevconsole use os._exit() when handle exception, and os._exit() required integer value. Looks like your package can't work within pydevconsole when DEBUG not defined in the ENV or set to false and SECRET_KEY not defined.
No worries! That sounds like it might be a bug their side then? If you could file an issue and link it here I'd love to follow along please :)
Thanks again!
I guess more generally it might be more friendly to throw an exception - would that be a helpful workaround for you? (I don't really understand the PyCharm issue you're having)
Yes, that pydev bug. pydev interpreter override exit function. See do_exit function. So when you pass string to sys.exit it throw TypeError exception.
@doismellburning throwing an exception is probably more friendly. It's also less opinionated, but I'm pretty sure it's the right way to go. Since the calling code might catch the exception, we should make it so that d12f doesn't load half of the settings
before raising the exception. I.e. the check for SECRET_KEY
should probably be the first thing that happens in factorise()
.