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

django-stubs 4.2.7 throws type check error for Group.user_set #1862

Closed
johnthagen opened this issue Dec 7, 2023 · 1 comment · Fixed by #1864
Closed

django-stubs 4.2.7 throws type check error for Group.user_set #1862

johnthagen opened this issue Dec 7, 2023 · 1 comment · Fixed by #1864
Labels
bug Something isn't working mypy-plugin Issues specific to mypy_django_plugin regression Behavior has changed for worse with a release

Comments

@johnthagen
Copy link

johnthagen commented Dec 7, 2023

Bug report

With django-stubs 4.2.6, the following simplified code type checked:

from django.contrib.auth.models import Group, User

group = Group()
group.user_set.add(User(username=""))

But with with 4.2.7:

$ mypy main.py 
main.py:4: error: "Group" has no attribute "user_set"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

How is that should be

I expect no type check error here. This seems to be a common way to get the Users of a Group:

System information

  • OS: macOS
  • python version: 3.10.13
  • django version: 4.2.8
  • mypy version: 1.7.1
  • django-stubs version: 4.2.7
  • django-stubs-ext version: 4.2.7

Configuration

[tool.mypy]
ignore_missing_imports = true
strict = true
disallow_subclassing_any = false
disallow_untyped_decorators = false
warn_return_any = false

plugins = [
    "pydantic.mypy",
    "mypy_django_plugin.main",
]

[tool.django-stubs]
django_settings_module = "config.settings"
@johnthagen johnthagen added the bug Something isn't working label Dec 7, 2023
@flaeppe
Copy link
Member

flaeppe commented Dec 7, 2023

Hm, we probably don't have cover for when a ManyToManyField is inherited via an abstract model.

django.contrib.auth.models.User inherits PermissionsMixin.groups which is what results in the user_set related manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mypy-plugin Issues specific to mypy_django_plugin regression Behavior has changed for worse with a release
Development

Successfully merging a pull request may close this issue.

3 participants