django-stubs icon indicating copy to clipboard operation
django-stubs copied to clipboard

Error typechecking ManyToManyField manager `request.user.groups.all()`

Open willbeaufoy opened this issue 2 years ago • 0 comments

Bug report

What's wrong

If I use request.user.groups.all() in a view (request being an instance of django.http.HttpRequest), this runs fine but mypy complains with

error: Item "ManyToManyField[Sequence[Group], RelatedManager[Group]]" of "Union[ManyToManyField[Sequence[Group], RelatedManager[Group]], EmptyManager]" has no attribute "all"

How is that should be

Typechecking should pass without errors.

System information

  • OS: Ubuntu 20.04
  • python version: 3.9.10
  • django version: 4.0.2
  • mypy version: 0.910
  • django-stubs version: 1.9.0
  • django-stubs-ext version: 0.3.1

willbeaufoy avatar Mar 24 '22 12:03 willbeaufoy