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

Passing iterable of integers to lookup model by ManyToManyField throws error in mypy #2243

Open
tbrlpld opened this issue Jun 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@tbrlpld
Copy link

tbrlpld commented Jun 30, 2024

Bug report

What's wrong

I have the following models

# matches/models.py

class MatchGroup(models.Model):
    members = models.ManyToManyField(
        to="users.User",
        related_name="match_groups",
    )

# users/models.py

class User(auth_models.AbstractBaseUser, auth_models.PermissionsMixin):
    # Details here should not be relevant.
    ...

When I look up a group by its users like so

user_ids = (1, 2)
group = MatchGroup.objects.get(members=user_ids)

I get the following error from mypy:

Incompatible type for lookup 'members': (got "tuple[int, int]", expected "User | int | None")  [misc]

How is that should be

Passing an iterable of integers to the lookup should be ok and not generate errors, because Django can deal with it.

System information

  • OS:
  • python version: 3.11
  • django version: 5.0.6
  • mypy version: 1.10.0
  • django-stubs version: 5.0.2
  • django-stubs-ext version: 5.0.2
@tbrlpld tbrlpld added the bug Something isn't working label Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant