django-stubs
django-stubs copied to clipboard
Incorrect typing for ManyToMany add()
Bug report
What's wrong
The typing of a ManyToMany relation's add() method incorrectly assumes that model ids are int, but they can be other types, such as UUID. Attempting to call add(model_id) causes a mypy error if the id is not an int:
Argument 1 has incompatible type "UUID"; expected "Union[FooModel, int]"
How is that should be
The add() method should accept the related model, and whatever the type of the related model's id is.