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

TypeError: listener() got an unexpected keyword argument 'priority'

allComputableThings opened this issue · comments

commented

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When I add sanic-ext to the requirements.txt to the docker image and run the image, I get:

TypeError: listener() got an unexpected keyword argument 'priority'

It runs fine when run directly (Python 3.10)

Perhaps this is an an issue using FROM sanicframework/sanic:3.8-latest (I following the Sanic docs on docker setup, then added sanic-ext to the project).

$ docker build -t my-sanic-image 
$ docker run --rm --name mysanic -p 8000:8000  my-sanic-image                                                                                                             
[2024-04-06 16:43:03 +0000] [1] [INFO] Sanic v23.3.0                                                                                                                                                       
[2024-04-06 16:43:03 +0000] [1] [INFO] Goin' Fast @ http://0.0.0.0:8000
[2024-04-06 16:43:03 +0000] [1] [INFO] mode: production, single worker
[2024-04-06 16:43:03 +0000] [1] [INFO] server: sanic, HTTP/1.1
[2024-04-06 16:43:03 +0000] [1] [INFO] python: 3.8.16
[2024-04-06 16:43:03 +0000] [1] [INFO] platform: Linux-6.5.0-26-generic-x86_64-with
[2024-04-06 16:43:03 +0000] [1] [INFO] packages: sanic-routing==22.8.0, sanic-ext==23.12.0
Traceback (most recent call last):
  File "server.py", line 11, in <module>
    app.run(host='0.0.0.0', port=8000)
  File "/usr/local/lib/python3.8/site-packages/sanic/mixins/startup.py", line 204, in run
    serve(primary=self)  # type: ignore
  File "/usr/local/lib/python3.8/site-packages/sanic/mixins/startup.py", line 740, in serve
    setup_ext(primary)
  File "/usr/local/lib/python3.8/site-packages/sanic/application/ext.py", line 32, in setup_ext
    app._ext = Ext(app, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/sanic_ext/bootstrap.py", line 112, in __init__
    extension._startup(self)
  File "/usr/local/lib/python3.8/site-packages/sanic_ext/extensions/base.py", line 45, in _startup
    self.startup(bootstrap)
  File "/usr/local/lib/python3.8/site-packages/sanic_ext/extensions/injection/extension.py", line 12, in startup
    add_injection(self.app, self.registry, self.constant_registry)
  File "/usr/local/lib/python3.8/site-packages/sanic_ext/extensions/injection/injector.py", line 21, in add_injection
    signature_registry = _setup_signature_registry(
  File "/usr/local/lib/python3.8/site-packages/sanic_ext/extensions/injection/injector.py", line 77, in _setup_signature_registry
    @app.listener("before_server_start", priority=PRIORITY - 1)
TypeError: listener() got an unexpected keyword argument 'priority'

Dockerfile

FROM sanicframework/sanic:3.8-latest

WORKDIR /sanic

COPY . .

RUN pip install -r requirements.txt

EXPOSE 8000

CMD ["python", "server.py"]

requirements.txt

sanic
sanic-ext

Also fails for sanic[ext]

server.py

from sanic import Sanic, text
# import sanicext

app = Sanic("MySanicApp")

@app.get('/')
async def hello(request):
    return text("OK!")

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

Code snippet

No response

Expected Behavior

No response

How do you run Sanic?

Sanic CLI

Operating System

Linux

Sanic Version

sanic --version Sanic 23.12.1; Routing 23.12.0

Additional context

No response

This is a support issues and not a bug.

TypeError: listener() got an unexpected keyword argument 'priority'