django-stubs icon indicating copy to clipboard operation
django-stubs copied to clipboard

Incorrect typing for ManyToMany add()

Open markedwards opened this issue 3 years ago • 3 comments

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.

markedwards avatar Jun 16 '22 15:06 markedwards