pytest-sanic
pytest-sanic copied to clipboard
Problem with sanic>21.6
Hey,
Thanks for the great library!
Seems like there is an error on sanic > 21.6
. The failure I see looks like that:
ERROR sanic.error:http_protocol.py:110 protocol.connection_task uncaught
Traceback (most recent call last):
File "/Users/rmk/projects/ets-labs/python-dependency-injector/venv/lib/python3.10/site-packages/sanic/server/protocols/http_protocol.py", line 101, in connection_task
await self.app.dispatch(
File "/Users/rmk/projects/ets-labs/python-dependency-injector/venv/lib/python3.10/site-packages/sanic/signals.py", line 163, in dispatch
return await dispatch
File "/Users/rmk/projects/ets-labs/python-dependency-injector/venv/lib/python3.10/site-packages/sanic/signals.py", line 111, in _dispatch
group, handlers, params = self.get(event, condition=condition)
File "/Users/rmk/projects/ets-labs/python-dependency-injector/venv/lib/python3.10/site-packages/sanic/signals.py", line 73, in get
group, param_basket = self.find_route(
TypeError: 'NoneType' object is not callable
ERROR asyncio:plugin.py:76 Task exception was never retrieved
future: <Task finished name='Task-19' coro=<HttpProtocol.connection_task() done, defined at /Users/rmk/projects/ets-labs/python-dependency-injector/venv/lib/python3.10/site-packages/sanic/server/protocols/http_protocol.py:92> exception=TypeError("'NoneType' object is not callable")>
Traceback (most recent call last):
File "/Users/rmk/projects/ets-labs/python-dependency-injector/venv/lib/python3.10/site-packages/sanic/server/protocols/http_protocol.py", line 130, in connection_task
await self.app.dispatch(
File "/Users/rmk/projects/ets-labs/python-dependency-injector/venv/lib/python3.10/site-packages/sanic/signals.py", line 163, in dispatch
return await dispatch
File "/Users/rmk/projects/ets-labs/python-dependency-injector/venv/lib/python3.10/site-packages/sanic/signals.py", line 111, in _dispatch
group, handlers, params = self.get(event, condition=condition)
File "/Users/rmk/projects/ets-labs/python-dependency-injector/venv/lib/python3.10/site-packages/sanic/signals.py", line 73, in get
group, param_basket = self.find_route(
TypeError: 'NoneType' object is not callable
The failure occurs all the time, but if you need an example, take a look at: https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/sanic
Thanks, Roman
We have the same problem 😬
Created a fix here but would need some feedback
Created a fix here but would need some feedback
The events system was overhauled in https://github.com/sanic-org/sanic/pull/2160
So you'll need to also add
await self.app._server_event("init", "before")
# Trigger after_start events
await self.app._server_event("init", "after")
after await self.app._startup()
This is a showstopper for me. This package is unusable without a fix for sanic 21 (working addition to changes)
await self.app._startup()
await self.app._server_event("init", "before", loop=self.loop)
# Trigger after_start events
await self.app._server_event("init", "after", loop=self.loop)
I've ported the fix from @wochinge to here https://github.com/yunstanford/pytest-sanic/pull/66 and added the changes you mentioned @autumnjolitz
Hi @melindaloubser1 , I managed to rederive the same fixes you made lol
Wasn't paying attention till Google's auth libraries made me upgrade and jesus christ wow the internal fiddling is awful
Im having this issue with signals -> find_route func is None, when running a test REST call using pytest-sanic 19, sanic-testing
Sanic version is 22.6.1
If Im trying to run with simply app.asgin_client.get(...) find_route is not None but im failing on
sanic.exceptions.SanicException: Loop can only be retrieved after the app has started running. Not supported with create_server
function
Can someone suggest a solution - im very blocked with Sanic version upgrade