litestar-org / litestar-fullstack

Litestar Fullstack Reference Application with React, Vite, SQLAlchemy, Docker, Task Queues, and more!
https://fullstack.litestar.dev/
MIT License
340 stars 56 forks source link

Bug: `app database upgrade` command not working #139

Closed sorasful closed 8 months ago

sorasful commented 8 months ago

Description

I've tried to setup this template and play a little bit with the commands. It seems that app database upgrade command does not work because the signature of one of the method is invalid.

I'm going to create a pull request for this.

URL to code causing the issue

No response

MCVE

# Your MCVE code here

Steps to reproduce

1. Clone the repository
2. run "make install"
3. run "app database upgrade"

Screenshots

No response

Logs

>> app database upgrade
Using Litestar app from env: 'app.asgi:app'
Cannot read Vite manifest file at /home/tevak/dev/litestar-fullstack/src/app/domain/web/public/manifest.json. Did you forget to build your assets?
Starting database upgrade process ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Are you sure you you want migrate the database to the `head` revision? [y/n]: y
DEBUG - 2024-03-23 12:59:39,864 - asyncio - selector_events - Using selector: EpollSelector
......
sqlite3.Connection object at 0x6fff0ee863e0>) completed
Traceback (most recent call last):
  File "/home/tevak/dev/litestar-fullstack/.venv/bin/app", line 8, in <module>
    sys.exit(run_cli())
             ^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/src/app/__main__.py", line 26, in run_cli
    run_litestar_cli()
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/litestar/__main__.py", line 6, in run_cli
    litestar_group()
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/rich_click/rich_command.py", line 126, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/litestar/cli/_utils.py", line 273, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/litestar/cli/_utils.py", line 273, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/advanced_alchemy/extensions/litestar/cli.py", line 109, in upgrade_database
    alembic_commands.upgrade(revision=revision, sql=sql, tag=tag)
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/advanced_alchemy/alembic/commands.py", line 92, in upgrade
    return migration_command.upgrade(config=self.config, revision=revision, tag=tag, sql=sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/alembic/command.py", line 403, in upgrade
    script.run_env()
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/alembic/script/base.py", line 583, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file
    module = load_module_py(module_id, path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/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 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/tevak/dev/litestar-fullstack/src/app/db/migrations/env.py", line 143, in <module>
    asyncio.run(run_migrations_online())
  File "/home/tevak/.pyenv/versions/3.11.4/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/tevak/.pyenv/versions/3.11.4/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/.pyenv/versions/3.11.4/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/src/app/db/migrations/env.py", line 135, in run_migrations_online
    await connection.run_sync(do_run_migrations)
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/ext/asyncio/engine.py", line 880, in run_sync
    return await greenlet_spawn(fn, self._proxied, *arg, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 186, in greenlet_spawn
    result = context.switch(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/src/app/db/migrations/env.py", line 106, in do_run_migrations
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/alembic/runtime/environment.py", line 948, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/alembic/runtime/migration.py", line 605, in run_migrations
    heads = self.get_current_heads()
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/alembic/runtime/migration.py", line 538, in get_current_heads
    if not self._has_version_table():
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/alembic/runtime/migration.py", line 555, in _has_version_table
    return sqla_compat._connectable_has_table(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/alembic/util/sqla_compat.py", line 301, in _connectable_has_table
    return inspect(connectable).has_table(tablename, schemaname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/engine/reflection.py", line 429, in has_table
    return self.dialect.has_table(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 2, in has_table
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/engine/reflection.py", line 97, in cache
    ret = fn(self, con, *args, **kw)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/sqlite/base.py", line 2150, in has_table
    info = self._get_table_pragma(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/sqlite/base.py", line 2771, in _get_table_pragma
    cursor = connection.exec_driver_sql(statement)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1782, in exec_driver_sql
    ret = self._execute_context(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1842, in _execute_context
    self._autobegin()
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 796, in _autobegin
    self.begin()
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 864, in begin
    self._transaction = RootTransaction(self)
                        ^^^^^^^^^^^^^^^^^^^^^
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 2684, in __init__
    self._connection_begin_impl()
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 2702, in _connection_begin_impl
    self.connection._begin_impl(self)
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1107, in _begin_impl
    self.dispatch.begin(self)
  File "/home/tevak/dev/litestar-fullstack/.venv/lib/python3.11/site-packages/sqlalchemy/event/attr.py", line 497, in __call__
    fn(*args, **kw)
TypeError: DatabaseSettings.get_engine.<locals>._sqla_on_begin() missing 1 required positional argument: '_'


### Package Version

2..7.0

### Platform

- [X] Linux
- [ ] Mac
- [ ] Windows
- [ ] Other (Please specify in the description above)