django12factor icon indicating copy to clipboard operation
django12factor copied to clipboard

wrong sys.exit argument

Open dlancer opened this issue 7 years ago • 6 comments

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.

dlancer avatar May 26 '17 19:05 dlancer

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

doismellburning avatar May 27 '17 00:05 doismellburning

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.

dlancer avatar May 27 '17 05:05 dlancer

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!

doismellburning avatar May 27 '17 08:05 doismellburning

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)

doismellburning avatar May 27 '17 08:05 doismellburning

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.

dlancer avatar May 27 '17 11:05 dlancer

@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().

jdelic avatar May 27 '17 12:05 jdelic