-
-
Notifications
You must be signed in to change notification settings - Fork 450
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
Mypy can't get custom manager type #1067
Comments
Hi @MaximShteygervald 🙂 We are working on better manager types in a new release, so it might be already fixed. |
I think this is related to #1023 and the fact that django-tenant-users is an untyped package. |
I'm trying to update django-stubs and ext, but I'm being blocked by this issue. We usually create a custom queryset and use class AttachmentQS(QuerySet['Attachment']):
def load(self, pk) -> 'Attachment': ...
class Attachment(Model):
# ...
objects: AttachmenQS = AttachmentQS.as_manager() # type: ignore This has worked pretty well so far, but trying to update apparently makes our hack being ignored and I get lots of issues like:
when calling |
Hi @flaeppe, Notice that issue is different in two regards:
In this case is the actual manager's type the one missing the methods in the queryset. The line that fails is calling Just to test, I did the change to use class AttachmentQS(QuerySet['Attachment']):
def load(self, pk) -> 'Attachment': ...
AttachmentManager = Manager.from_queryset(AttachmentQS)
class Attachment(Model):
# ...
objects = AttachmentManager() And still the same error is reported. |
I fear this is overwritten by the plugin code (at least when using
If you got that error without an explicit annotation, there's probably a bug somewhere. |
Oh! I've just realized that I did a slightly different thing: objects = Manager.from_queryset(AttachmentQS)() Which issues this warning:
Extracting the manager, does solve this particular issue. |
I had the very same issue with django-safedelete. My solution was a PR against upstream makinacorpus/django-safedelete#213 . Thankfully it got merged quickly. |
In my opinion Manager generic should accept Model, Quesryset[Model] types allowing to specify any class that extends Quesryset[Model] as the queryset |
What is the first link supposed to communicate? The answer to the question is just "if you're doing this [example] or [this]" but there's no consequent: if you're doing this things … then what? The PR in the second link has been merged, but I still get errors: first, a 'need type annotation for "objects"' error when doing |
I think the revision behind the link said something different than today, at the time the comment was written. Before support for
It's really hard to say anything without more context. Feel free to post an example, repro case or any other context that you think could be useful to help hunt down the cause of the issue you're seeing. |
Yeah, I eventually worked out how to do what I wanted as I attempted to repro and discovered that the actual case depends on the fact that the model in question is a |
I have custom user model that inherits from UserProfile from django-tenant-users package. UserProfile has custom model manager. In my model I see an error from mypy:
Mypy: Could not resolve manager type for "Flow_BE.applications.users.models.User.objects"
and when i try to use this manager I receive error:
Mypy: "Manager[User]" has no attribute "create_user"
This is how models specified:
For User.objects.create_user(...) mypy generates errors. Code works.
System information
python
version: 3.10.4django
version: 4.0.6mypy
version: 0.971django-stubs
version: 1.12.0django-stubs-ext
version: 0.5.0The text was updated successfully, but these errors were encountered: