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 RelatedManager not callable #1191

Merged

Conversation

UnknownPlatypus
Copy link
Contributor

I have made things!

mypy raise an exception when we try to call a RelatedManager. However, django allows that.

Here is a minimal reproducible exemple:

from django.db import models 
from django.contrib.auth.models import User

class CustomUser(User):
    staffs = models.Manager()
    
class SalesMan(models.Model):
    client = models.ManyToManyField(CustomUser)


sales_man = SalesMan.objects.first()

reveal_type(sales_man.client) # Revealed type is "django.db.models.manager.RelatedManager[test.t.CustomUser]"
sales_man.agent(manager="staffs") # error: "RelatedManager[CustomUser]" not callable

I added the missing stubs and a test validating it was failing before and passing after this patch.

Related issues

None

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 👍

@sobolevn sobolevn merged commit 14ff5ad into typeddjango:master Oct 19, 2022
@UnknownPlatypus UnknownPlatypus deleted the fix_related_manager_not_callable branch October 19, 2022 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants