sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.

Home Page:https://sanic.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't use optional CLI arguments

ruckc opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When I try sanic module:app it works.
When I try sanic -d module:app it doesn't. Trying --dev doesn't work. I can run with -r and --debug separately.

$ sanic testapp:app --dev
[2024-01-04 15:39:58 -0500] [19499] [INFO] 
  ┌─────────────────────────────────────────────────────────────────────────────────────────────────────┐
  │                                            Sanic v23.12.0                                           │
  │                                  Goin' Fast @ http://127.0.0.1:8000                                 │
  ├───────────────────────┬─────────────────────────────────────────────────────────────────────────────┤
  │                       │         app: testapp                                                        │
  │     ▄███ █████ ██     │        mode: debug, single worker                                           │
  │    ██                 │      server: sanic, HTTP/1.1                                                │
  │     ▀███████ ███▄     │      python: 3.10.12                                                        │
  │                 ██    │    platform: Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35 │
  │    ████ ████████▀     │ auto-reload: enabled                                                        │
  │                       │    packages: sanic-routing==23.12.0, sanic-ext==23.12.0                     │
  │ Build Fast. Run Fast. │                                                                             │
  └───────────────────────┴─────────────────────────────────────────────────────────────────────────────┘

[2024-01-04 15:39:58 -0500] [19499] [DEBUG] Creating multiprocessing context using 'spawn'
[2024-01-04 15:39:58 -0500] [19499] [ERROR] Experienced exception while trying to serve
Traceback (most recent call last):
  File "/home/python/virtualenvs/testapp/lib/python3.10/site-packages/sanic/mixins/startup.py", line 1144, in serve
    trigger_events(ready, loop, primary)
  File "/home/python/virtualenvs/testapp/lib/python3.10/site-packages/sanic/server/events.py", line 35, in trigger_events
    loop.run_until_complete(result)
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/home/python/virtualenvs/testapp/lib/python3.10/site-packages/sanic/cli/app.py", line 160, in start_repl
    SanicREPL(app, self.args.repl).run()
  File "/home/python/virtualenvs/testapp/lib/python3.10/site-packages/sanic/cli/console.py", line 134, in __init__
    del variable_descriptions[3]
IndexError: list assignment index out of range
[2024-01-04 15:39:58 -0500] [19499] [INFO] Server Stopped
[2024-01-04 15:39:58 -0500] [19499] [DEBUG] Annyeong
Traceback (most recent call last):
  File "/home/python/virtualenvs/testapp/bin/sanic", line 8, in <module>
    sys.exit(main())
  File "/home/python/virtualenvs/testapp/lib/python3.10/site-packages/sanic/__main__.py", line 12, in main
    cli.run(args)
  File "/home/python/virtualenvs/testapp/lib/python3.10/site-packages/sanic/cli/app.py", line 121, in run
    serve(app)
  File "/home/python/virtualenvs/testapp/lib/python3.10/site-packages/sanic/mixins/startup.py", line 1144, in serve
    trigger_events(ready, loop, primary)
  File "/home/python/virtualenvs/testapp/lib/python3.10/site-packages/sanic/server/events.py", line 35, in trigger_events
    loop.run_until_complete(result)
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/home/python/virtualenvs/testapp/lib/python3.10/site-packages/sanic/cli/app.py", line 160, in start_repl
    SanicREPL(app, self.args.repl).run()
  File "/home/python/virtualenvs/testapp/lib/python3.10/site-packages/sanic/cli/console.py", line 134, in __init__
    del variable_descriptions[3]
IndexError: list assignment index out of range

Code snippet

No response

Expected Behavior

No response

How do you run Sanic?

Sanic CLI

Operating System

Linux

Sanic Version

23.12.0

Additional context

No response

Any more specifics about the OS? I ran into something similar today when running in docker and I assumed it was because of something with stdin.

In short, you can solve by adding --no-repl for right now.

Just WSL2, Ubuntu 23.10, Windows 11

variable_descriptions is a static list of length 3. There is no [3] index to do del variable_descriptions[3].

        variable_descriptions = [
            f"  - {Colors.BOLD + Colors.SANIC}app{Colors.END}: The Sanic application instance - {Colors.BOLD + Colors.BLUE}{str(app)}{Colors.END}",  # noqa: E501
            f"  - {Colors.BOLD + Colors.SANIC}sanic{Colors.END}: The Sanic module - {Colors.BOLD + Colors.BLUE}import sanic{Colors.END}",  # noqa: E501
            f"  - {Colors.BOLD + Colors.SANIC}do{Colors.END}: An async function to fake a request to the application - {Colors.BOLD + Colors.BLUE}Result(request, response){Colors.END}",  # noqa: E501
        ]

there is a quick 'solution' without any changes of the current code: pip3 install httpx :)