﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
8467	For ManyToMany manager, we should convert objects being added or removed to the pk type if they are not.	Wonlay	nobody	"For example:
{{{
class A(models.Model):
	name = models.CharField(blank=True)

class B(models.Model):
	a = models.ManyToManyField(A)

a = A(name='aaa')
a.save()
b = B()
b.save()

# This line works fine:
b.a.add('1')

# But this one will raise 'Duplicate entry' error:
b.a.add('1')
}}}

This is caused by {{{ '1' }}} is not an integer, the duplication checking code in {{{ add() }}} fails when checking the string type {{{'1'}}}.

The same problem is applied to the {{{ remove() }}} method.

If we convert the objects to its pk type of the model, code will run correctly.

And my patch is attached."	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed	Duplicate entry, add, remove, ManyToManyField	wonlay@…	Accepted	1	0	0	0	0	0
