Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - Creating a new shopping list doesn't work #3288

Closed
5 of 6 tasks
ursuad opened this issue Mar 11, 2024 · 4 comments · Fixed by #3290
Closed
5 of 6 tasks

[BUG] - Creating a new shopping list doesn't work #3288

ursuad opened this issue Mar 11, 2024 · 4 comments · Fixed by #3290
Labels
bug: confirmed bug Something isn't working

Comments

@ursuad
Copy link

ursuad commented Mar 11, 2024

First Check

  • This is not a feature request.
  • I added a very descriptive title to this issue (title field is above this).
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Mealie documentation, with the integrated search.
  • I already read the docs and didn't find an answer.
  • This issue can be replicated on the demo site (https://demo.mealie.io/).

What is the issue you are experiencing?

I'm trying to create a new shopping list but no shopping list gets created and I can't see any shopping lists once I clicked "Create", even if the "Show all" option is enabled.
I'm using Mealie together with PostgreSQL database.

Steps to Reproduce

Log in -> go to shopping lists -> Click on "Create" button and give it a descriptive name -> click Create

There is no error in the UI, but the shopping list doesn't get created. I can see some errors in the logs though.

Please provide relevant logs

When the Docker container starts, I can see the following:

Switching to dedicated user

        User uid:    1000
        User gid:    1000

INFO: 11-Mar-24 18:53:04 	Database connection established.
INFO: 11-Mar-24 18:53:04 	Context impl PostgresqlImpl.
INFO: 11-Mar-24 18:53:04 	Will assume transactional DDL.
INFO: 11-Mar-24 18:53:04 	Migration needed. Performing migration...
INFO: 11-Mar-24 18:53:04 	Context impl PostgresqlImpl.
INFO: 11-Mar-24 18:53:04 	Will assume transactional DDL.
INFO: 11-Mar-24 18:53:04 	Running upgrade ba1e4a6cfe99 -> 2298bb460ffd, added user to shopping list
Traceback (most recent call last):
  File "/app/alembic/versions/2024-02-23-16.15.07_2298bb460ffd_added_user_to_shopping_list.py", line 40, in find_user_id_for_group
    user_id = session.execute(sa.text(stmt).bindparams(group_id=group_id)).scalar_one()
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 1464, in scalar_one
    return self._only_one_row(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 752, in _only_one_row
    raise exc.NoResultFound(
sqlalchemy.exc.NoResultFound: No row was found when one was required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/mealie/db/init_db.py", line 119, in <module>
    main()
  File "/app/mealie/db/init_db.py", line 101, in main
    command.upgrade(alembic_cfg, "head")
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/alembic/command.py", line 403, in upgrade
    script.run_env()
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/alembic/script/base.py", line 583, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file
    module = load_module_py(module_id, path)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 113, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/app/alembic/env.py", line 77, in <module>
    run_migrations_online()
  File "/app/alembic/env.py", line 71, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/alembic/runtime/environment.py", line 948, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/alembic/runtime/migration.py", line 627, in run_migrations
    step.migration_fn(**kw)
  File "/app/alembic/versions/2024-02-23-16.15.07_2298bb460ffd_added_user_to_shopping_list.py", line 73, in upgrade
    populate_shopping_list_users()
  File "/app/alembic/versions/2024-02-23-16.15.07_2298bb460ffd_added_user_to_shopping_list.py", line 56, in populate_shopping_list_users
    user_id = find_user_id_for_group(group_id)
  File "/app/alembic/versions/2024-02-23-16.15.07_2298bb460ffd_added_user_to_shopping_list.py", line 45, in find_user_id_for_group
    ).scalar_one()
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 1464, in scalar_one
    return self._only_one_row(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 752, in _only_one_row
    raise exc.NoResultFound(
sqlalchemy.exc.NoResultFound: No row was found when one was required
INFO:     Started server process [1]
INFO:     Waiting for application startup.
INFO: 11-Mar-24 18:53:09 	-----SYSTEM STARTUP-----

Also, in the docker logs, when I click on the "Create" shopping list I can see the following logs:

INFO:     172.70.90.167:0 - "POST /api/groups/shopping/lists HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1970, in _exec_single_context
    self.dialect.do_execute(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 924, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.UndefinedColumn: column "user_id" of relation "shopping_lists" does not exist
LINE 1: INSERT INTO shopping_lists (id, group_id, user_id, name, cre...
                                                  ^


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

Traceback (most recent call last):
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 412, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
    return await self.app(scope, receive, send)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 24, in __call__
    await responder(scope, receive, send)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 44, in __call__
    await self.app(scope, receive, self.send_with_gzip)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/routing.py", line 758, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/routing.py", line 778, in app
    await route.handle(scope, receive, send)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/routing.py", line 299, in handle
    await self.app(scope, receive, send)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/routing.py", line 79, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/routing.py", line 74, in app
    response = await func(request)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 278, in app
    raw_response = await run_endpoint_function(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 193, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/starlette/concurrency.py", line 42, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/anyio/to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "/app/mealie/routes/groups/controller_shopping_lists.py", line 182, in create_one
    shopping_list = self.service.create_one_list(data)
  File "/app/mealie/services/group_services/shopping_lists.py", line 481, in create_one_list
    new_list = self.shopping_lists.create(create_data)  # type: ignore
  File "/app/mealie/repos/repository_generic.py", line 171, in create
    self.session.commit()
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1972, in commit
    trans.commit(_to_root=True)
  File "<string>", line 2, in commit
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
    ret_value = fn(self, *arg, **kw)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1257, in commit
    self._prepare_impl()
  File "<string>", line 2, in _prepare_impl
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
    ret_value = fn(self, *arg, **kw)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1232, in _prepare_impl
    self.session.flush()
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 4296, in flush
    self._flush(objects)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 4431, in _flush
    with util.safe_reraise():
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 4392, in _flush
    flush_context.execute()
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 466, in execute
    rec.execute(self)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 642, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 93, in save_obj
    _emit_insert_statements(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 1233, in _emit_insert_statements
    result = connection.execute(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1421, in execute
    return meth(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 514, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1643, in _execute_clauseelement
    ret = self._execute_context(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1849, in _execute_context
    return self._exec_single_context(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1989, in _exec_single_context
    self._handle_dbapi_exception(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2356, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1970, in _exec_single_context
    self.dialect.do_execute(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 924, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column "user_id" of relation "shopping_lists" does not exist
LINE 1: INSERT INTO shopping_lists (id, group_id, user_id, name, cre...
                                                  ^

[SQL: INSERT INTO shopping_lists (id, group_id, user_id, name, created_at, update_at) VALUES (%(id)s::UUID, %(group_id)s::UUID, %(user_id)s::UUID, %(name)s, %(created_at)s, %(update_at)s)]
[parameters: {'id': 'e19b7c37-1cac-4a2f-bfd2-129be805f676', 'group_id': 'a1a4e15e-f35a-4547-8740-a8a7782cab5a', 'user_id': '93710d1e-24db-49cf-956a-3f4c22f3a305', 'name': 'Hmm', 'created_at': datetime.datetime(2024, 3, 11, 18, 42, 18, 46147), 'update_at': datetime.datetime(2024, 3, 11, 18, 42, 18, 46149)}]
(Background on this error at: https://sqlalche.me/e/20/f405)
INFO:     127.0.0.1:59414 - "GET /api/app/about HTTP/1.1" 200 OK

Mealie Version

PostgreSQL docker image tag: postgres:15
Mealie Docker image tag: ghcr.io/mealie-recipes/mealie:v1.3.2

Deployment

Docker (Linux)

Additional Deployment Details

I've just upgraded mealie from version 1.2.0 to 1.3.2

@ursuad ursuad added bug Something isn't working triage labels Mar 11, 2024
@michael-genson
Copy link
Collaborator

Are you able to revert back to 1.2.0 and verify that the app works fine? Also, while on 1.2.0, can you provide a backup file?

@ursuad
Copy link
Author

ursuad commented Mar 11, 2024

Sure thing.
Just reverted to 1.2.0 and everything seems to work fine (regarding shopping lists) and I created and downloaded a backup file. It's attached here.
mealie_2024.03.11.19.41.18.zip

@michael-genson
Copy link
Collaborator

Perfect, thanks! Looking at this now

@michael-genson
Copy link
Collaborator

It looks like you don't have any users in the "Home" group, which results in the shopping list failing to be assigned an owner during the migration. In this case, I imagine we just need to delete the shopping list (if there are no users in that group, you're probably not using the shopping list).

I'll open a PR to do that automatically. You can either wait for the next release with that PR merged, or you can either:

  1. Add a user to the "Home" group before migrating to 1.3
  2. Delete the shopping list (by either adding a temporary user to that group and having them delete it, or just removing it from the database)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: confirmed bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants