App unconditionally executes DB statements on startup
With the current master, running yarn dev:mysql-init
fails with the error pymysql.err.ProgrammingError: (1146, "Table 'course.grader' doesn't exist")
. This also occurs in production.
Full traceback
yarn dev:mysql-init (zesje-dev)
yarn run v1.22.19
$ yarn dev:mysql create && sleep 2 && yarn dev:mysql-migrate
$ ZESJE_SETTINGS=$(pwd)/zesje_dev_cfg.py python3 -m zesje.mysql create
Initializing MySQL...
mysqld --defaults-file=/home/anton/Bot/coding/zesje/mysql.conf --datadir=/home/anton/Bot/coding/zesje/data-dev/mysql --basedir=$CONDA_PREFIX/bin --lc-messages-dir=$CONDA_PREFIX/share/mysql --plugin-dir=$CONDA_PREFIX/lib/plugin --init-file=/home/anton/Bot/coding/zesje/myinit.sql --initialize
$ yarn dev:mysql is-running && (yarn dev:migrate || true) || ((yarn dev:mysql start && sleep 2 && yarn dev:migrate); yarn dev:mysql stop)
$ ZESJE_SETTINGS=$(pwd)/zesje_dev_cfg.py python3 -m zesje.mysql is-running
MySQL is not running
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
$ ZESJE_SETTINGS=$(pwd)/zesje_dev_cfg.py python3 -m zesje.mysql start
mysqld --defaults-file=/home/anton/Bot/coding/zesje/mysql.conf --datadir=/home/anton/Bot/coding/zesje/data-dev/mysql --basedir=$CONDA_PREFIX/bin --lc-messages-dir=$CONDA_PREFIX/share/mysql --plugin-dir=$CONDA_PREFIX/lib/plugin --gdb
$ ZESJE_SETTINGS=$(pwd)/zesje_dev_cfg.py FLASK_APP=zesje.wsgi:app flask db upgrade
Traceback (most recent call last):
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
self.dialect.do_execute(
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
cursor.execute(statement, parameters)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/cursors.py", line 153, in execute
result = self._query(query)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/cursors.py", line 322, in _query
conn.query(q)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/connections.py", line 558, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/connections.py", line 822, in _read_query_result
result.read()
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/connections.py", line 1200, in read
first_packet = self.connection._read_packet()
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/connections.py", line 772, in _read_packet
packet.raise_for_error()
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (1146, "Table 'course.grader' doesn't exist")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/anton/micromamba/envs/zesje-dev/bin/flask", line 8, in <module>
sys.exit(main())
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/flask/cli.py", line 1064, in main
cli.main()
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/flask/cli.py", line 355, in decorator
app = __ctx.ensure_object(ScriptInfo).load_app()
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/flask/cli.py", line 309, in load_app
app = locate_app(import_name, name)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/flask/cli.py", line 219, in locate_app
__import__(module_name)
File "/home/anton/Bot/coding/zesje/zesje/wsgi.py", line 4, in <module>
app = factory.create_app(celery=celery)
File "/home/anton/Bot/coding/zesje/zesje/factory.py", line 42, in create_app
if Grader.query.filter(Grader.oauth_id == app.config["OWNER_OAUTH_ID"]).one_or_none() is None:
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 2850, in one_or_none
return self._iter().one_or_none()
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 2916, in _iter
result = self.session.execute(
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1717, in execute
result = conn._execute_20(statement, params or {}, execution_options)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1710, in _execute_20
return meth(self, args_10style, kwargs_10style, execution_options)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 334, in _execute_on_connection
return connection._execute_clauseelement(
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1577, in _execute_clauseelement
ret = self._execute_context(
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1953, in _execute_context
self._handle_dbapi_exception(
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2134, in _handle_dbapi_exception
util.raise_(
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
raise exception
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
self.dialect.do_execute(
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
cursor.execute(statement, parameters)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/cursors.py", line 153, in execute
result = self._query(query)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/cursors.py", line 322, in _query
conn.query(q)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/connections.py", line 558, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/connections.py", line 822, in _read_query_result
result.read()
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/connections.py", line 1200, in read
first_packet = self.connection._read_packet()
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/connections.py", line 772, in _read_packet
packet.raise_for_error()
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "/home/anton/micromamba/envs/zesje-dev/lib/python3.9/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1146, "Table 'course.grader' doesn't exist")
[SQL: SELECT grader.id AS grader_id, grader.name AS grader_name, grader.oauth_id AS grader_oauth_id, grader.internal AS grader_internal
FROM grader
WHERE grader.oauth_id = %(oauth_id_1)s]
[parameters: {'oauth_id_1': 'admin@admin'}]