fatal error in email encryption function
during the user registration flow, the application crashes when trying to access the email encryption password. i tracked it down to this line of code. the env
variable is an empty dict, but i've confirmed that the environment variables are set, and the app.config
dict is populated properly.
i think the issue is that env
is imported before the environment is fully configured, and python caches the import so tor_weather.utilities.encryption:env
is never populated.
Traceback (most recent call last):
File "/home/weather/.tor-weather-virtualenv/lib/python3.9/site-packages/flask/app.py", line 1517, in full_dispatch_request
rv = self.dispatch_request()
File "/home/weather/.tor-weather-virtualenv/lib/python3.9/site-packages/flask/app.py", line 1503, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/home/weather/.tor-weather-virtualenv/lib/python3.9/site-packages/flask_restx/api.py", line 405, in wrapper
resp = resource(*args, **kwargs)
File "/home/weather/.tor-weather-virtualenv/lib/python3.9/site-packages/flask/views.py", line 84, in view
return current_app.ensure_sync(self.dispatch_request)(*args, **kwargs)
File "/home/weather/.tor-weather-virtualenv/lib/python3.9/site-packages/flask_restx/resource.py", line 46, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/weather/tor-weather/tor_weather/resources/external_api_routes/register_user.py", line 32, in post
return User().register(email, password)
File "/home/weather/tor-weather/tor_weather/service/user.py", line 127, in register
self._send_email_verification_code(email)
File "/home/weather/tor-weather/tor_weather/service/user.py", line 77, in _send_email_verification_code
verification_code = self._generate_email_verification_code(email)
File "/home/weather/tor-weather/tor_weather/service/user.py", line 47, in _generate_email_verification_code
email_verification_code = encrypt(email)
File "/home/weather/tor-weather/tor_weather/utilities/encryption.py", line 11, in encrypt
secret: str = env["EMAIL_ENCRYPT_PASS"]
KeyError: 'EMAIL_ENCRYPT_PASS'