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: 1.11 breaks hello world #367

Closed
peterschutt opened this issue Aug 14, 2022 · 1 comment
Closed

Bug: 1.11 breaks hello world #367

peterschutt opened this issue Aug 14, 2022 · 1 comment
Labels
Bug 🐛 This is something that is not working as expected

Comments

@peterschutt
Copy link
Contributor

"""
Minimal Starlite application.
"""
from typing import Any

from starlite import Starlite, get


@get("/")
def hello_world() -> dict[str, Any]:
    """Hi"""
    return {"hello": "world"}


app = Starlite(route_handlers=[hello_world])
(starlite-hello-world-nPMVAxaQ-py3.10) peter@peter-Inspiron-15-5510:~/PycharmProjects/starlite-hello-world$ poetry run uvicorn main:app
Traceback (most recent call last):
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/bin/uvicorn", line 8, in <module>
    sys.exit(main())
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/uvicorn/main.py", line 407, in main
    run(
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/uvicorn/main.py", line 575, in run
    server.run()
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/uvicorn/server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/home/peter/.pyenv/versions/3.10.5/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/home/peter/.pyenv/versions/3.10.5/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/uvicorn/server.py", line 67, in serve
    config.load()
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/uvicorn/config.py", line 479, in load
    self.loaded_app = import_from_string(self.app)
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/uvicorn/importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
  File "/home/peter/.pyenv/versions/3.10.5/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/peter/PycharmProjects/starlite-hello-world/./main.py", line 15, in <module>
    app = Starlite(route_handlers=[hello_world])
  File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
  File "pydantic/decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call
  File "pydantic/decorator.py", line 201, in pydantic.decorator.ValidatedFunction.execute
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/starlite/app.py", line 165, in __init__
    super().__init__(
  File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
  File "pydantic/decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call
  File "pydantic/decorator.py", line 201, in pydantic.decorator.ValidatedFunction.execute
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/starlite/router.py", line 134, in __init__
    self.register(value=route_handler)
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/starlite/app.py", line 231, in register
    route_handler.resolve_response_handler()
  File "/home/peter/.cache/pypoetry/virtualenvs/starlite-hello-world-nPMVAxaQ-py3.10/lib/python3.10/site-packages/starlite/handlers/http.py", line 493, in resolve_response_handler
    if isclass(self.signature.return_annotation) and issubclass(
  File "/home/peter/.pyenv/versions/3.10.5/lib/python3.10/abc.py", line 123, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class

I think it is any route that returns a collection as the current app I'm working on runs if I remove any routes returning collections such as:

    @lib.get_collection()
    async def list_providers(self, service: providers.Service) -> list[providers.Schema]:
        """A paginated list of all registered providers"""
        return await service.list()
@peterschutt peterschutt added the Bug 🐛 This is something that is not working as expected label Aug 14, 2022
@peterschutt
Copy link
Contributor Author

>>> from typing import Any, Dict
>>> import inspect
>>> builtin_alias = dict[str, Any]
>>> typing_alias = Dict[str, Any]
>>> inspect.isclass(builtin_alias)
True
>>> inspect.isclass(typing_alias)
False

I guess the reason that this wasn't picked up in tests is because we always use the generic collection types imported from typing in our tests for backwards compatibility. We probably need to add some tests that only run on 3.9+ that use the generic builtin types.

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

2 participants