@mikael unfortunately yes, it seems you need it if the function has the @click.command decorator. Although in this case init_db_command is just a thin wrapper over another function init_db, so you can get around it by just calling init_db directly instead.

Also I think I was wrong that you don't need the environment variable, as well, because I just tried running that code again and it didn't work. I'm guessing I must have had the variable still hanging around from a previous run, so it looked like I didn't need it, but alas. Again though, in this particular case, you can get around it by using init_db and wrapping in the app context. If you're using the command directly though, wrapping with the app context does nothing; you need the environment variable. Hope that makes sense.