Describe the bug
multidict project just released (1 hour ago) their version 4.7.0 (https://pypi.org/project/multidict/#history), this includes a change that breaks Sanic Header class definition.
----> 1 import sanic
/usr/local/lib/python3.7/site-packages/sanic/__init__.py in <module>
1 from sanic.__version__ import __version__
----> 2 from sanic.app import Sanic
3 from sanic.blueprints import Blueprint
4
5
/usr/local/lib/python3.7/site-packages/sanic/app.py in <module>
16
17 from sanic import reloader_helpers
---> 18 from sanic.asgi import ASGIApp
19 from sanic.blueprint_group import BlueprintGroup
20 from sanic.config import BASE_LOGO, Config
/usr/local/lib/python3.7/site-packages/sanic/asgi.py in <module>
20 import sanic.app # noqa
21
---> 22 from sanic.compat import Header
23 from sanic.exceptions import InvalidUsage, ServerError
24 from sanic.log import logger
/usr/local/lib/python3.7/site-packages/sanic/compat.py in <module>
2
3
----> 4 class Header(CIMultiDict):
5 def get_all(self, key):
6 return self.getall(key, default=[])
TypeError: type 'multidict._multidict.CIMultiDict' is not an acceptable base type
Code snippet
$ pip install -U multidict==4.7.0
$ python -m sanic
Expected behavior
Sanic module imports correctly.
Environment (please complete the following information):
Additional context
No extra context
I get the same thing in my CI builds:
from sanic.response import HTTPResponse
/usr/local/lib/python3.6/site-packages/sanic/__init__.py:2: in <module>
from sanic.app import Sanic
/usr/local/lib/python3.6/site-packages/sanic/app.py:18: in <module>
from sanic.asgi import ASGIApp
/usr/local/lib/python3.6/site-packages/sanic/asgi.py:22: in <module>
from sanic.compat import Header
/usr/local/lib/python3.6/site-packages/sanic/compat.py:4: in <module>
class Header(CIMultiDict):
E TypeError: type 'multidict._multidict.CIMultiDict' is not an acceptable base type
Environment (please complete the following information):
Downgrading to multidict==4.6.1 fixes the problem.
The error occurs because the cimultidict_type does not have the Py_TPFLAGS_BASETYPE flag set ...
cimultidict_type without Py_TPFLAGS_BASETYPE
https://github.com/aio-libs/multidict/blob/d786088778285ba56e06c992f44e546fb4c7b74b/multidict/_multidict.c#L1007
multidict_type with Py_TPFLAGS_BASETYPE
https://github.com/aio-libs/multidict/blob/d786088778285ba56e06c992f44e546fb4c7b74b/multidict/_multidict.c#L948
I reported the issue https://github.com/aio-libs/multidict/issues/416 and made a PR I also made a PR https://github.com/aio-libs/multidict/pull/417 ... a lot of boilerplate for 44 bytes
Only the latest Sanic version 19.9.0 fail as well as 19.6.3. Version 19.6.2 (and older) works well with multidict==4.7.0.
Also, interestingly, both 19.9.0 and 19.6.3 work on my machine with my local Python 3.8.0 (built with pyenv, Mac OS 10.15), but both don't work in the official Python Docker image 3.8.
Here am also getting the same issue
File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/src/app.py", line 1, in <module>
from sanic import Sanic, response
File "/root/.local/share/virtualenvs/lib/python3.7/site-packages/sanic/__init__.py", line 2, in <module> from sanic.app import Sanic
File "/root/.local/share/virtualenvs/lib/python3.7/site-packages/sanic/app.py", line 18, in <module>
from sanic.asgi import ASGIApp
File "/root/.local/share/virtualenvs/lib/python3.7/site-packages/sanic/asgi.py", line 22, in <module>
from sanic.compat import Header
File "/root/.local/share/virtualenvs/lib/python3.7/site-packages/sanic/compat.py", line 4, in <module>
class Header(CIMultiDict):
TypeError: type 'multidict._multidict.CIMultiDict' is not an acceptable base type
am using python 3.7.2 version and sanic=* is in my pipfile
which version of sanic i should use here ?
Sanic version 19.6.2 work on my machine
downgrading multidict to 4.6.1 fixed the problem for me!
My PR is merged - hope 4.7.1 will come out soon
Thanks all for these responses.. multidict 4.6.1 is working for me.
@qwesda, I confirm the error is gone with the new multidict==4.7.1.
Thanks!
Downgrading to
multidict==4.6.1fixes the problem.
requires 4.7.1 or above
Has anyone run Sanic with multidict==4.7.1?
@ahopkins, I'm using it, no issues so far.
Most helpful comment
My PR is merged - hope 4.7.1 will come out soon