django-ninja-extra MRO Bug
Hope you can reproduce this. docker container setup with celery workers:
All celery workers failed to start with: TypeError: Cannot create a consistent method resolution order (MRO).
The root cause looks might be that django-ninja-extra>=0.21 introduced a change to PaginatedResponseSchema that inherits from both Generic and BasePaginatedResponseSchema in a way that creates an invalid Python class hierarchy with certain Pydantic versions.
What fixed it for me:
before: django-ninja==1.5.0 django-ninja-extra==0.30.6 django-ninja-jwt==5.4.2
after (= fix): django-ninja==1.2.0 django-ninja-extra==0.20.9 django-ninja-jwt==5.4.2
Thank you
@sebieire
What's your Pydantic version and Python version
I'm running into the same issue, Here are the potentially relevant versions in my case:
django==6.0 django-ninja==1.5.1 django-ninja-extra==0.18.4 django-ninja-jwt==5.2.7 pydantic==2.12.5 pydantic-core==2.41.5 pydantic-graph==1.29.0
And here is the relevant traceback:
File "./.venv/lib/python3.13/site-packages/ninja_extra/__init__.py", line 7, in <module>
from ninja_extra.controllers import (
...<8 lines>...
)
File "./.venv/lib/python3.13/site-packages/ninja_extra/controllers/__init__.py", line 1, in <module>
from .base import ControllerBase, api_controller
File "./.venv/lib/python3.13/site-packages/ninja_extra/controllers/base.py", line 35, in <module>
from ninja_extra.operation import ControllerPathView, Operation
File "./.venv/lib/python3.13/site-packages/ninja_extra/operation.py", line 39, in <module>
from .controllers.route.context import RouteContext, get_route_execution_context
File "./.venv/lib/python3.13/site-packages/ninja_extra/controllers/route/__init__.py", line 9, in <module>
from ninja_extra.controllers.response import ControllerResponse, ControllerResponseMeta
File "./.venv/lib/python3.13/site-packages/ninja_extra/controllers/response.py", line 17, in <module>
from ..schemas import DetailSchema, IdSchema, OkSchema
File "./.venv/lib/python3.13/site-packages/ninja_extra/schemas/__init__.py", line 1, in <module>
from .response import (
...<6 lines>...
)
File "./.venv/lib/python3.13/site-packages/ninja_extra/schemas/response.py", line 75, in <module>
class PaginatedResponseSchema(
...<2 lines>...
results: List[T]
File "./.venv/lib/python3.13/site-packages/ninja/schema.py", line 181, in __new__
result = super().__new__(cls, name, bases, namespace, **kwargs)
File "./.venv/lib/python3.13/site-packages/pydantic/_internal/_model_construction.py", line 155, in __new__
cls = cast('type[BaseModel]', super().__new__(mcs, cls_name, bases, namespace, **kwargs))
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen abc>", line 106, in __new__
TypeError: Cannot create a consistent method resolution order (MRO) for bases BaseModel, Generic, BasePaginatedResponseSchema
I realize that the ninja-extra version above is outdated, but this was the result of the env resolution when using uv to upgrade dependencies. Digging further and trying to enforce later versions, I frequently get errors that uv cannot satisfy the dependency requirements, e.g. because django-ninja-extra>=0.30.5 depends on django-ninja==1.5.0 so that e.g. 1.5.1 is incompatible.
By experimenting, the following dependency specification:
django>=5.2
django-ninja>=1.5
django-ninja-jwt>=5.4
pydantic[email]>=2.12
can be resolved to:
django==5.2.9
django-ninja==1.5.0
django-ninja-jwt==5.4.2
django-ninja-extra==0.30.6
pydantic==2.12.5
pydantic-core==2.41.5
...
And this works correctly for me!
This finding seems to contradict the OP as the versions are the same? So, I'm not sure if the root cause is the same after all. In my case, the issue was probably down to the dependency specification interplay between django-ninja , django-ninja-extra and django-ninja-jwt that allowed for this issue to surface.
Okay. Thanks for taking your time to debug this. I will try upgrade to ninja 1.5.1 and django 6.0. Then I will revert back to you so you can try the latest release.
THere is a new realease now https://github.com/eadwinCode/django-ninja-extra/releases/tag/0.30.8 Check and see if there issue has been resolved
Thanks @eadwinCode , the issue is fixed with the 0.30.8 release and it passes our test suite. Looking forward to the PyPI release.
Thanks for bringing this to my notice. Will fix that shortly
Resolved