django-stubs: Could not resolve manager type for "core.models.FooModel.objects" [django-manager-missing]
Bug report
I’ve updated django-stubs-ext from 0.4.0 to 0.5.0 and got a lof of error messages from mypy. Before, mypy didn’t complain
There might actually be nothing wrong with django-stubs, but maybe I need to add a type annotation. The problem is that I have no idea what I need to change.
The code has many unit tests. It’s very unlikely that all of those locations mypy now complains about actually have issues that would prevent proper code execution.
What’s wrong
mypy shows several django-manager-missing errors.
How is that should be
No mypy errors shown
System information
- OS: Ubuntu
pythonversion: 3.8djangoversion: 3.2mypyversion: 0.942django-stubsversion: 1.12.0django-stubs-extversion: 0.5.0
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 19
- Comments: 24 (9 by maintainers)
Commits related to this issue
- FIX: Mypy Errors due to Django Money Django money causes django-manager-missing error in mypy. Issue is here - https://github.com/typeddjango/django-stubs/issues/1023 — committed to emoss08/Trenova by emoss08 4 years ago
- MONTA-T-39 (#68) * CHANGE: Settings to include audit log. * CHANGE: Create system user command - Remove multiple stdout - Add tests for command * ADD: Celery Tasks for clearing audit logs Add - C... — committed to emoss08/Trenova by emoss08 4 years ago
Our case is something like
No django-money.
Any updates on this? Is there a workaround? We’re hitting this issue with a model inheriting 2 of our own abstract classes and no untyped/mistyped third party packages in the chain. I tried adding the type hints to the model to represent the relationship but that doesn’t seem to work.
I am running into this problem when using
django-modeltranslation.type(Model.objects)returns<class 'modeltranslation.manager.MultilingualManager'>.Is there any workaround that I could do or is this something that would need to be fixed within
django-modeltranslation?Then it’s definitely related to https://github.com/typeddjango/django-stubs/pull/993#issuecomment-1155151881 and django-money not exporting types.
I’m afraid it’s not much to do other than ignoring the error until django-money starts to export types. At least as far as I’m aware
Having the same issue as @mschoettle , using
django-modeltranslationand getting thedjango-manager-missingerrorHi, I’m also using
django-money==3.0.0and I bump into the same problem. It actually blocks me from updating not only thedjango-stubsversion but themypyone as well.Is there any temporary workaround?
If anyone doesn’t know: you can ignore this error by adding a
# type: ignore[django-manager-missing]to the lines that are reported on mypy (usually the class declaration line in a class that is the target of a ForeignKey from a model with untyped / dinamically added managers as it happens on the reverse relation).I’m still on 4.0.0, but for me
ForeignKeyrelations only trigger this issue when the model you’re creating the ForeignKey from has a field has a dinamically added / untyped manager. Counterintuitively, the issue is not caused by managers on the model that’s the target the error is reported on. AFAIK the workaround is to add a type ignore as specified above.Also hitting this issue: originally I thought problem was inheriting from
model_utils.TimeStampedModelbut after removing this base class the issue persists. I have also tried the workaround withdjango_stubs_ext.db.models.manager.RelatedManager. Currently at least with5.0.4it appears there is no way to use this library withForeignKeyrelations in Django?Same issue with django-modeltrans. Ive opened an issue there but I just found this one.
In case it helps, I’ve got a minimal project reproducing the issue with that library: https://github.com/browniebroke/modeltrans-mypy-bug
I would like to add that we have the same issue with another untyped library that provides Model base classes.
Since it is not possible to suppress the error in mypy and there seems to be no other workaround, this is a complete blocker for us to switch to 1.12.0