Fails in Linode Marketplace on Debian 9 due to incompatible Python and Flask-WTF versions
Hoping this is the right place to mention this (I could not find Flask-on-Linode on https://github.com/linode/Marketplace-Apps, for example)
I've had some trouble diagnosing 502s I get out of the box when installing through Linode Marketplace, although it comes with the correct configuration as described here.
After much confusion I realised the reason is the flask server is constantly getting restarted after failing with:
$ cat /var/log/flask_app/flask_app.err.log
SyntaxError: invalid syntax
[2021-07-24 23:42:51 +0000] [19401] [INFO] Worker exiting (pid: 19401)
/usr/local/lib/python3.5/dist-packages/flask_sqlalchemy/__init__.py:873: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
[2021-07-24 23:42:51 +0000] [19402] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/lib/python3/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python3/dist-packages/gunicorn/util.py", line 384, in import_app
__import__(module)
File "/home/flask_app_project/flask_app/__init__.py", line 14, in <module>
from flask_app import routes
File "/home/flask_app_project/flask_app/routes.py", line 7, in <module>
from flask_app.forms import PostForm
File "/home/flask_app_project/flask_app/forms.py", line 1, in <module>
from flask_wtf import FlaskForm
File "/usr/local/lib/python3.5/dist-packages/flask_wtf/__init__.py", line 1, in <module>
from .csrf import CSRFProtect, CsrfProtect
File "/usr/local/lib/python3.5/dist-packages/flask_wtf/csrf.py", line 220
dest = f'{view.__module__}.{view.__name__}'
The reason is that the installed version of Flask-WTF uses f-syntax for strings (f'Here's the value of {something}'), which came in in Python 3.6.
$ pip freeze | grep WTF
Flask-WTF==0.15.0
WTForms==2.3.3
$ python3 --version
Python 3.5.3
0.15 has officially dropped support for 3.5 (https://github.com/wtforms/flask-wtf/pull/416) and the very next release (0.15.1) adds a python_requires to disallow installation on 3.5: https://flask-wtf.readthedocs.io/en/0.15.x/changes/#version-0-15-1
Possible fixes would be:
- Upgrading python to 3.6. The Linode marketplace suggests this app with Debian 9 only, where python 3.6 doesn't seem to be included out-of-the-box (
apt-cache search python3 | grep 3.6shows no results). I'm not sure where this is set up for the standard server that comes up via Linode Marketplace? - Downgrading Flask-WTF by explicitly requiring
Flask-WTF<0.15.0in requirements.txt (I've tested this and it works)
On an entirely separate note, may I suggest an addition to the otherwise great deployment notes on allowing incoming TCP traffic from ufw via something like ufw allow from <your-ip> to <linode-ip> proto tcp port 80? This is not entirely obvious to noobs like me.
Thanks for the nice example app and detailed explanation on setting it up.