You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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:
Context:
Class
has aManyToManyField
relationship with theUser
model throughClassMembership
, which also has an additionalrole
field.How is that should be
ManyRelatedManager
methodsadd
,set
and async equivalents should have an additional keyword argumentthrough_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
python
version: 3.12.1django
version: 5.0mypy
version: 1.7.1django-stubs
version: 4.2.7django-stubs-ext
version: 4.2.7The text was updated successfully, but these errors were encountered: