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

ManyToManyField constructor type doesn't expect 'null' keyword argument, even though it can be passed #2505

Open
lev-blit opened this issue Feb 10, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@lev-blit
Copy link

Bug report

What's wrong

When defining a model like this:

from django.db import models

class Person(models.Model):
    first_name = models.TextField(max_length=30)
    last_name = models.TextField(max_length=30)
    friends = models.ManyToManyField("self", null=True, blank=True)

which is technically valid in Django, running mypy on this file with django-stubs installed produces the following error:

$ mypy myapp/models.py --cache-dir /dev/null
myapp/models.py:7: error: Unexpected keyword argument "null" for "ManyToManyField"  [call-arg]
/home/user/workspace/django-example/venv/lib/python3.12/site-packages/django-stubs/db/models/fields/related.pyi:256: note: "ManyToManyField" defined here

It is passed as a kwarg from ManyToManyField's constructor to RelatedField's constructor, from where it is (still) passed as a kwarg to Field's constructor, where it is defined as an argument to the function (link to relevant stub)

How is that should be

The type stubs in ManyToManyField should probably reflect all arguments that can be passed as kwargs all the way down to Field's constructor.

System information

  • OS: Linux x86_64
  • python version: 3.12.4
  • django version: 5.1.6
  • mypy version: 1.15.0
  • django-stubs version: 5.1.3
  • django-stubs-ext version: 5.1.3
@lev-blit lev-blit added the bug Something isn't working label Feb 10, 2025
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