Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix manager interface type overrides #761

Closed
wants to merge 1 commit into from
Closed

Conversation

shosca
Copy link

@shosca shosca commented Sep 26, 2024

Fixes return type overrides of MultilingualManager.get_queryset and MultilingualQuerysetManager.get_queryset

fixes #760

@last-partizan
Copy link
Collaborator

Are you sure it fixes it?

I have tried with django-model-utils==5.0.0 and issues still exists.

I added a test into master, you can use:

pytest modeltranslation/tests/test_compat.py -v

Make sure to have latest django-model-utils installed in venv. Old versions does not have this bug.

@shosca
Copy link
Author

shosca commented Sep 28, 2024

We don't use django-model-utils but our situaton is similar in that we have our own flavor of SoftDeleteManager where get_queryset() is declared as

    def get_queryset(self) -> models.QuerySet[TModel]:
        ....

and i think django-model-utils suffers the same issue of overloading the return type as well: https://github.com/jazzband/django-model-utils/blob/d1eb8004f2ebe7524c4de6da9960cd48788953c3/model_utils/managers.py#L398 breaking the manager interface

Our mypy issue with latest django-modeltranslation is basically the same error error: Definition of "get_queryset" in base class "SoftDeleteManager" is incompatible with definition in base class "MultilingualManager" which is happening because of the return type overload on get_queryset() breaking manager interface and gets resolved once the return type is set as Queryset[TModel]

@last-partizan
Copy link
Collaborator

Can you show all related code?

MultilingualManager is supposed to be completely transparent to the end-user app code.

@shosca
Copy link
Author

shosca commented Sep 29, 2024

Can you show all related code?

MultilingualManager is supposed to be completely transparent to the end-user app code.

Sure, i've created a repo that reproduces our mypy issues here: https://github.com/shosca/repro_761

@last-partizan
Copy link
Collaborator

In that repo, you're using django-model-utils, and you said earlier you don't use it.

You don't need to subclass MultilingualManager in your app code, just remove it and django-modeltranslation takes care of the rest.

If you really need to subclass it, then - add # type: ignore comment for that line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: __class__ assignment: 'NewMultilingualManager' object layout differs from 'SoftDeletableManager'
2 participants