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: NameError when running litestar run on Windows systems #3991

Closed
1 of 4 tasks
EliseyGodX opened this issue Feb 11, 2025 · 2 comments
Closed
1 of 4 tasks

Bug: NameError when running litestar run on Windows systems #3991

EliseyGodX opened this issue Feb 11, 2025 · 2 comments
Labels
Bug 🐛 This is something that is not working as expected

Comments

@EliseyGodX
Copy link

Description

Bug Report: NameError when running litestar run on Windows systems

Description

When running the command litestar run on Windows systems (the bug is reproducible on both Windows 11 and Windows 2022), in a project with two files importing from Litestar (for example, main.py with from litestar import Litestar and controllers.py with from litestar.controller import Controller), the following exception occurs NameError: name 'AfterRequestHookHandler' is not defined.


Reproduction repository:

https://github.com/EliseyGodX/litestar_win_bug

URL to code causing the issue

https://github.com/EliseyGodX/litestar_win_bug/actions

MCVE

# Structure
app/
├── main.py
└── controllers.py

# main.py
from litestar import Litestar
app = Litestar()

# controllers.py
from litestar.controller import Controller

# Error
NameError: name 'AfterRequestHookHandler' is not defined

Steps to reproduce

Screenshots

Logs

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Scripts\litestar.exe\__main__.py", line 7, in <module>
    sys.exit(run_cli())
             ~~~~~~~^^
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Lib\site-packages\litestar\__main__.py", line 6, in run_cli
    litestar_group()
    ~~~~~~~~~~~~~~^^
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Lib\site-packages\rich_click\rich_command.py", line 367, in __call__
    return super().__call__(*args, **kwargs)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Lib\site-packages\click\core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Lib\site-packages\rich_click\rich_command.py", line 151, in main
    with self.make_context(prog_name, args, **extra) as ctx:
         ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Lib\site-packages\litestar\cli\_utils.py", line 224, in make_context
    self._prepare(ctx)
    ~~~~~~~~~~~~~^^^^^
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Lib\site-packages\litestar\cli\_utils.py", line 206, in _prepare
    env = ctx.obj = LitestarEnv.from_env(ctx.params.get("app_path"), ctx.params.get("app_dir"))
                    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Lib\site-packages\litestar\cli\_utils.py", line 114, in from_env
    loaded_app = _autodiscover_app(cwd)
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Lib\site-packages\litestar\cli\_utils.py", line 340, in _autodiscover_app
    get_type_hints(value, include_extras=True).get("return") if hasattr(value, "__annotations__") else None
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Lib\typing.py", line 2457, in get_type_hints
    value = _eval_type(value, base_globals, base_locals, base.__type_params__)
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Lib\typing.py", line 474, in _eval_type
    return t._evaluate(globalns, localns, type_params, recursive_guard=recursive_guard)
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\hostedtoolcache\windows\Python\3.13.1\x64\Lib\typing.py", line 1081, in _evaluate
    eval(self.__forward_code__, globalns, localns),
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 1, in <module>
NameError: name 'AfterRequestHookHandler' is not defined

Litestar Version

2.13, 2.14

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)
@EliseyGodX EliseyGodX added the Bug 🐛 This is something that is not working as expected label Feb 11, 2025
@euri10
Copy link
Contributor

euri10 commented Feb 11, 2025

I dont have windows but this seems like a duplicate of #3895

you may try renaming your app folder in the meantie as a workaround

@provinzkraut
Copy link
Member

Yeah, this is a duplicate of #3895

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected
Projects
None yet
Development

No branches or pull requests

3 participants