evereux / flicket

Simple ticket system using python flask
MIT License
128 stars 58 forks source link

setup (flask db upgrade) with Postgres crashing at 36c91aa9b3b5_new_action_model.py #80

Open herman-hellenes opened 1 month ago

herman-hellenes commented 1 month ago

Hi! I'm trying to get flicket connected to my hosted Postgres db (at Render.com), where I am facing some challenges debugging. Setting up flicket with default settings locally (MySQL) have worked excellent, and thanks a lot for your effort into creating this.

So, after setting up config.json, installing driver etc, I run flask db upgrade to set up the required tables, with the following log:

` C:\Users\Q0V\OneDrive - Storebrand\Documents\GitHub\test_ficket\flicket> flask db upgrade INFO [alembic.runtime.migration] Context impl PostgresqlImpl. INFO [alembic.runtime.migration] Will assume transactional DDL. INFO [alembic.runtime.migration] Running upgrade -> fe0f77ef3f46, migrations before source code control INFO [alembic.runtime.migration] Running upgrade fe0f77ef3f46 -> 36c91aa9b3b5, new action model Traceback (most recent call last): File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\sqlalchemy\engine\base.py", line 1969, in _exec_single_context
self.dialect.do_execute( File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\sqlalchemy\engine\default.py", line 922, in do_execute cursor.execute(statement, parameters) psycopg2.errors.UndefinedFunction: operator does not exist: boolean + boolean LINE 1: ...licket_ticket_action WHERE (assigned IS NOT NULL) + (claimed... ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "C:\Users\Q0V\AppData\Local\anaconda3\Scripts\flask.exe__main.py", line 7, in File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\flask\cli.py", line 1064, in main cli.main() File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\click\core.py", line 1078, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\click\core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\click\core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\click\core.py", line 1434, in invoke return ctx.invoke(self.callback, **ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\click\core.py", line 783, in invoke return callback(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\click\decorators.py", line 33, in new_func return f(get_current_context(), *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\flask\cli.py", line 358, in decorator return __ctx.invoke(f, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\click\core.py", line 783, in invoke return callback(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\flask_migrate\cli.py", line 150, in upgrade _upgrade(directory, revision, sql, tag, x_arg) File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\flask_migrate__init__.py", line 111, in wrapped f(args, **kwargs) File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\flask_migrate\init__.py", line 200, in upgrade command.upgrade(config, revision, sql=sql, tag=tag) File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\alembic\command.py", line 406, in upgrade script.run_env() File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\alembic\script\base.py", line 586, in run_env util.load_python_file(self.dir, "env.py") File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\alembic\util\pyfiles.py", line 95, in load_python_file module = load_module_py(module_id, path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\alembic\util\pyfiles.py", line 113, in load_module_py spec.loader.exec_module(module) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "C:\Users\Q0V\OneDrive - Storebrand\Documents\GitHub\test_ficket\flicket\migrations\env.py", line 87, in
run_migrations_online() File "C:\Users\Q0V\OneDrive - Storebrand\Documents\GitHub\test_ficket\flicket\migrations\env.py", line 80, in run_migrations_online context.run_migrations() File "", line 8, in run_migrations File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\alembic\runtime\environment.py", line 946, in run_migrations
self.get_context().run_migrations(kw) File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\alembic\runtime\migration.py", line 628, in run_migrations
step.migration_fn(
kw) File "C:\Users\Q0V\OneDrive - Storebrand\Documents\GitHub\test_ficket\flicket\migrations\versions\36c91aa9b3b5_new_action_model.py", line 23, in upgrade r = conn.execute(sa.text("SELECT COUNT(id) FROM flicket_ticket_action WHERE (assigned IS NOT NULL) " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\sqlalchemy\engine\base.py", line 1416, in execute return meth( ^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\sqlalchemy\sql\elements.py", line 516, in _execute_on_connection return connection._execute_clauseelement( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\sqlalchemy\engine\base.py", line 1639, in _execute_clauseelement ret = self._execute_context( ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\sqlalchemy\engine\base.py", line 1848, in _execute_context
return self._exec_single_context( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Q0V\AppData\Local\anaconda3\Lib\site-packages\sqlalchemy\engine\base.py", line 1988, in _exec_single_context
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.

[SQL: SELECT COUNT(id) FROM flicket_ticket_action WHERE (assigned IS NOT NULL) + (claimed IS NOT NULL) + (released IS NOT NULL) + (closed IS NOT NULL) + (opened IS NOT NULL) + (status IS NOT NULL) + (priority IS NOT NULL) != 1] (Background on this error at: https://sqlalche.me/e/20/f405) `

evereux commented 1 month ago

Yeah, there's definitely a problem with PostGreSQL here and I'm not entirely sure what the "correct" solution to fix this right now is.

The initial problem code is in 36c91aa9b3b5_new_action_model.py.


# check if it is possible to migrate
    r = conn.execute(sa.text("SELECT COUNT(id) FROM flicket_ticket_action WHERE (assigned IS NOT NULL) "
            "+ (claimed IS NOT NULL) + (released IS NOT NULL) + (closed IS NOT NULL) "
            "+ (opened IS NOT NULL) + (status IS NOT NULL) + (priority IS NOT NULL) != 1"))

If you are starting from a new database you don't need to do this so I tried commenting this out and running the upgrade. However, there is then another error in 9e59e0b9d1cf_last_updated.py where a simple query seems to just hang the migration script. I have thoughts on why this but can't (no time to) test it right now.

To get this working you could try the following, but it's hacky (please note only suitable for new databases):

\<edit> additional step

\</edit>

This will cause problems for future migrations if I add them but it's pretty easy to fix that by hacking at the version stamps.

evereux commented 1 month ago

There was a follow up post that @herman-hellenes asked regarding populating the database with defaults which seems to have been deleted.

For anyone else following this, once you have done flask db upgrade you can then continue with the installation instructions by then doing flask run-set-up.

herman-hellenes commented 1 month ago

Yeah correct @evereux , that works great! Only change is to do "flask db migrate -m "Initial migration." instead of "flask db -m "initial migrate", then at least it all worked for me, followed bu flask run-set-up.

evereux commented 1 month ago

flask db -m "initial migrate"

oops, I'll correct my post