Conversation
|
We need to update the documentation to indicate that admins should add a |
|
The variable is added automatically in the .env file at launch if no secret key is defined. |
Ah yes I forgot about this. I thought it was going to be re-generated everytime instead of being written. Not sure if we want to document it then. |
…ady exist, otherwise use exsiting key
73e615b to
eecd4fc
Compare
|
Why do we use I feel like it just adds a useless package. We are already manually parsing the I think we could simply checks for the environment variable. Maybe something like: env_secret = os.environ.get("SECRET_KEY")
if env_secret:
SECRET_KEY = env_secret
else:
SECRET_KEY = get_random_secret_key()
with open(".env", "a") as f:
f.write(f"\nSECRET_KEY={SECRET_KEY}\n")Also, a nice call from #2232 is that it was updating |
While we do read the lines in the files, it stores the whole line into the variable, so if we find the SECRET_KEY we would need to remove SECRET_KEY=' and the last ' before assigning it in Django Also, I saw from your last commit that you removed |
I just edited my comment for more details. About |
|
By the way I tested it and it seems to work fine, I am just nitpicking on details |
This code would not work since the base.py is loaded multiple times during launch (and everytime we do so Django commands through manage.py like shell_plus or migrations) With your code, the secret key will keep getting written in the .env file until you restart the Django containers and make the secret key variable an environnement variable. So you end up with multiple secret keys in the .env As for #2232 putting the generation inside a docker entry point, it means that in the future, when we make Codabench binaries and don't rely on docker (or podman), the secret key generation won't work. |
|
@ObadaS OK, thank you for the explanation. On my side I think it is ready to be merged. |
A brief description of the purpose of the changes contained in this PR.
Automatically generate Django's Secret Key if it does not exist inside the .env file, otherwise use the given secret key
Alternative to #2232
Checklist