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

Missing keyword argument "through_defaults" on ManyRelatedManager methods #1919

Closed
sgorawski opened this issue Jan 24, 2024 · 0 comments · Fixed by #1943
Closed

Missing keyword argument "through_defaults" on ManyRelatedManager methods #1919

sgorawski opened this issue Jan 24, 2024 · 0 comments · Fixed by #1943
Labels
bug Something isn't working

Comments

@sgorawski
Copy link

Bug report

What's wrong

Mypy raises an error when using through_defaults on a many to many field manager.

The code works fine on Django 5.0 and is documented here: https://docs.djangoproject.com/en/5.0/topics/db/models/#extra-fields-on-many-to-many-relationships.

Example error:

tests/test_assignments.py:93: error: Unexpected keyword argument "through_defaults" for "add" of "ManyRelatedManager" [call-arg]
        cls.members.add(user, through_defaults={'role': ClassMembership.Role.STUDENT})
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Context: Class has a ManyToManyField relationship with the User model through ClassMembership, which also has an additional role field.

How is that should be

ManyRelatedManager methods add, set and async equivalents should have an additional keyword argument through_defaults.
The type should be dict[str, Any], I suppose.

File: django-stubs/db/models/fields/related_descriptors.pyi.

Django docs: https://docs.djangoproject.com/en/5.0/topics/db/models/#extra-fields-on-many-to-many-relationships.

System information

  • OS: MacOS 14.2.1
  • python version: 3.12.1
  • django version: 5.0
  • mypy version: 1.7.1
  • django-stubs version: 4.2.7
  • django-stubs-ext version: 4.2.7
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

Successfully merging a pull request may close this issue.

1 participant