rio-labs / rio

WebApps in pure Python. No JavaScript, HTML and CSS needed
https://rio.dev
Apache License 2.0
1.95k stars 69 forks source link

[BUG]: Errors when running with Version 0.10.7 #163

Closed unoctanium closed 2 hours ago

unoctanium commented 2 weeks ago

Describe the bug

Getting KeyError: '__main__' when I run a rio app with latest rio-ui version from pipy (0.10.7) With 0.10.4 everything worked well

Steps to Reproduce

First attempt: upgraded rio-ui to 0.10.7 in existing project Second attempt: Created a new environment and installed rio-ui 0.10.7 and created an empty project

Screenshots/Videos

No response

Operating System

Linux

What browsers are you seeing the problem on?

Chrome

Browser version

No response

What device are you using?

Desktop, Mobile

Additional context

Starting...
Warning: Debug mode is enabled.
Warning: Debug mode includes helpful tools for development, but is slower and disables some safety checks. Never use it in production!
Warning: Run with `--release` to disable debug mode.

Warning: Running in public mode. All devices on your network can access the app.
Warning: Only run in public mode if you trust your network!
Warning: Run without `--public` to limit access to this device.

The app is running at http://172.31.196.91:8000

🗨  Join other Developers on Discord — https://discord.gg/7ejXaPwhyH
✨ Star Rio on GitHub — https://github.com/rio-labs/rio
🐞 Report a bug — https://github.com/rio-labs/rio/issues/new/choose
📣 Spread the word
Exception in ASGI application
Traceback (most recent call last):
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 411, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/rio/cli/run_project/uvicorn_worker.py", line 65, in _asgi_shim
    await self.app_server(scope, receive, send)
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/rio/app_server/fastapi_server.py", line 346, in __call__
    return await super().__call__(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
               ^^^^^^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/fastapi/routing.py", line 301, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/fastapi/routing.py", line 212, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/rio/app_server/fastapi_server.py", line 501, in _serve_index
    inspection.get_child_component_containing_attribute_names_for_builtin_components()
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/rio/inspection.py", line 102, in get_child_component_containing_attribute_names_for_builtin_components
    cls._unique_id_: get_child_component_containing_attribute_names(cls)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/rio/inspection.py", line 70, in get_child_component_containing_attribute_names
    for attr_name, serializer in serialization.get_attribute_serializers(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/rio/serialization.py", line 197, in get_attribute_serializers
    serializer = _get_serializer_for_annotation(annotations[attr_name])
                                                ~~~~~~~~~~~^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/rio/inspection.py", line 40, in __getitem__
    return introspection.typing.resolve_forward_refs(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/introspection/typing/misc.py", line 178, in resolve_forward_refs
    from ._utils import ImporterDict
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/introspection/__init__.py", line 7, in <module>
    from .parameter import *
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/introspection/parameter.py", line 6, in <module>
    from .types import ForwardRefContext
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/introspection/types.py", line 19, in <module>
    NONE = sentinel.create("NONE")
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/sentinel.py", line 84, in create
    "__module__": _get_caller_module(),
                  ^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/Rio1/.pythonlibs/lib/python3.12/site-packages/sentinel.py", line 144, in _get_caller_module
    stack = inspect.stack()
            ^^^^^^^^^^^^^^^
  File "/nix/store/pn7dhmavkjq85nhpj7lvn0ir1bp58zyd-python3-3.12.5/lib/python3.12/inspect.py", line 1777, in stack
    return getouterframes(sys._getframe(1), context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/pn7dhmavkjq85nhpj7lvn0ir1bp58zyd-python3-3.12.5/lib/python3.12/inspect.py", line 1752, in getouterframes
    traceback_info = getframeinfo(frame, context)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/pn7dhmavkjq85nhpj7lvn0ir1bp58zyd-python3-3.12.5/lib/python3.12/inspect.py", line 1710, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
               ^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/pn7dhmavkjq85nhpj7lvn0ir1bp58zyd-python3-3.12.5/lib/python3.12/inspect.py", line 970, in getsourcefile
    module = getmodule(object, filename)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/pn7dhmavkjq85nhpj7lvn0ir1bp58zyd-python3-3.12.5/lib/python3.12/inspect.py", line 1020, in getmodule
    main = sys.modules['__main__']
           ~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '__main__'
Aran-Fey commented 2 weeks ago

Are you using a virtual environment? If yes, what files exist in the virtual env's directory?

unoctanium commented 2 weeks ago

Good hint. I am testing on Replit. that is NixOs. And I use poetry. And yes. Has something to do with the environment. As a test case, now I have set up a brand new Replit python environment and then it works. I will try to find out what needs to be updated with poetry in an existing environment. For now, I have a workaround with setting up a new dev environment from scratch.

Aran-Fey commented 2 weeks ago

We just published a pre-release (0.10.8rc0) that should hopefully fix this issue. Please let us know if this works for you.