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

Fastapi display in viewer does not work on Ubuntu #4949

Closed
testlabauto opened this issue Oct 8, 2024 · 8 comments
Closed

Fastapi display in viewer does not work on Ubuntu #4949

testlabauto opened this issue Oct 8, 2024 · 8 comments

Comments

@testlabauto
Copy link
Contributor

System details:

Positron and OS details:

Ubuntu 24.04
Positron 2024.11.0 build 16

Interpreter details:

Python 3.10.12

Describe the issue:

The fastapi_example from qa-example-content does not render in the Viewer on Ubuntu.

Steps to reproduce the issue:

  1. Clone qa-example-content
  2. Run fastapi_example
  3. Note that the viewer url shows http://127.0.0.1:8000/docs but nothing is displayed

Expected or desired behavior:

FastAPI example works

Were there any error messages in the UI, Output panel, or Developer Tools console?

Uncaught SyntaxError: Identifier 'hostMessaging' has already been declared

@testlabauto
Copy link
Contributor Author

FYI @seeM @isabelizimm

@jonvanausdeln
Copy link
Contributor

On my windows box I get

C:\Users\JonVanausdeln\source\qa-example-content [main ≡ +0 ~1 -0 !]> C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\python.exe -m uvicorn --reload workspaces/python_apps/fastapi_example.fastapi_example:app
INFO:     Will watch for changes in these directories: ['C:\\Users\\JonVanausdeln\\source\\qa-example-content']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [5648] using WatchFiles
Process SpawnProcess-1:
Traceback (most recent call last):
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\multiprocessing\process.py", line 314, in _bootstrap
    self.run()
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\_subprocess.py", line 80, in subprocess_started
    target(sockets=sockets)
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\asyncio\runners.py", line 118, in run    
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\asyncio\base_events.py", line 685, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\server.py", line 69, in serve
    await self._serve(sockets)
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\server.py", line 76, in _serve
    config.load()
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\config.py", line 434, in load
    self.loaded_app = import_from_string(self.app)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\importer.py", line 22, in import_from_string
    raise exc from None
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\importer.py", line 19, in import_from_string
    module = importlib.import_module(module_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'workspaces/python_apps/fastapi_example'

@juliasilge juliasilge added the area: viewer Issues related to Viewer category. label Oct 8, 2024
@seeM
Copy link
Contributor

seeM commented Oct 9, 2024

@jonvanausdeln this looks like a separate Windows-specific issue where our conversion from a file path (workspaces/python_apps/fastapi_example/fastapi_example.py) to a Python module import path (workspaces.python_apps.fastapi_example.fastapi_example) is not working as expected.

I'm not yet sure what's happening in the Ubuntu case.

@jonvanausdeln
Copy link
Contributor

@seeM , should I open a separate issue for windows?

@seeM
Copy link
Contributor

seeM commented Oct 10, 2024

@jonvanausdeln yes I think so

@sharon-wang
Copy link
Member

@testlabauto was this intermittent or consistently reproducible? I wonder if this is the same issue as #5187. I re-enabled the Fastapi test in #5265 which passed in the PR test run.

sharon-wang added a commit that referenced this issue Nov 6, 2024
- addresses #5187
- ❓ possibly also addresses
#4949

### Implementation Notes
- adds optional `appReadyMessage` property to `RunAppOptions` and
`DebugAppOptions`
- specify an `appReadyMessage` of `'Application startup complete'` for
FastAPI and Shiny apps, which leverage uvicorn and output that message
when the app is ready
- delete empty `DebugConfiguration` object from the
`positron-run-app.d.ts` files, as I think they are unused?
- modified the logging level in `api.ts` for a few messages
- `previewUrlInExecutionOutput` now checks for both the app url and the
`appReadyMessage` if provided,
    - an app is considered ready if:
- the `appReadyMessage` was not provided and the app url has been
matched; or
- the `appReadyMessage` was provided and matched, and the app url has
been matched
- if the `appReadyMessage` was provided but not matched, and the app url
has been matched, we'll time out of the `raceTimeout`, but the url will
have been matched, so we'll still try to open the app in the Viewer

### QA Notes

- I've renabled `Python - Verify Basic FastAPI App [C903306]` which now
passes
- Please use the repro steps from the issue:
#5187
@sharon-wang
Copy link
Member

The Fastapi Python Application test is now passing on main:

Image

I think this is now fixed -- moving to verification!

@sharon-wang sharon-wang self-assigned this Nov 6, 2024
sharon-wang added a commit that referenced this issue Nov 6, 2024
- addresses #5187
- ❓ possibly also addresses
#4949

### Implementation Notes
- adds optional `appReadyMessage` property to `RunAppOptions` and
`DebugAppOptions`
- specify an `appReadyMessage` of `'Application startup complete'` for
FastAPI and Shiny apps, which leverage uvicorn and output that message
when the app is ready
- delete empty `DebugConfiguration` object from the
`positron-run-app.d.ts` files, as I think they are unused?
- modified the logging level in `api.ts` for a few messages
- `previewUrlInExecutionOutput` now checks for both the app url and the
`appReadyMessage` if provided,
    - an app is considered ready if:
- the `appReadyMessage` was not provided and the app url has been
matched; or
- the `appReadyMessage` was provided and matched, and the app url has
been matched
- if the `appReadyMessage` was provided but not matched, and the app url
has been matched, we'll time out of the `raceTimeout`, but the url will
have been matched, so we'll still try to open the app in the Viewer

### QA Notes

- I've renabled `Python - Verify Basic FastAPI App [C903306]` which now
passes
- Please use the repro steps from the issue:
#5187
@testlabauto
Copy link
Contributor Author

Verified Fixed

Positron Version(s) : 2024.12.0-12
OS Version          : Ubuntu

Test scenario(s)

Marking as verified based on CI test passing now!

Link(s) to TestRail test cases run or created:

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants