﻿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
20742	ModelForm primary_key update with instance set is executed as INSERT caused by is_valid() changing the instance	amin@…	nobody	"I do agree this is a bad database design but it's executed without any warning or anything in the docs so i want to open this ticket to allow the discussion of raising an Error or anything (e.g. an info in the docs @primary_key or modelform) not let anyone run into this mistake.

{{{
#!python
class Test(models.Model):
  email = models.CharField(max_length=100, primary_key=True)

class TestForm(forms.ModelForm):
  class Meta:
     model = Test 

# assuming this object exists
x = Test.objects.get(email='old@example.com')

form = TestForm(email='new@example.com', instance=x)

# here instance is updated with new@example.com as pkey and django thinks it has to create a new model instance not updating the old instance

if form.is_valid():
   new_x = form.save()
   new_x.save()
}}}"	Bug	closed	Database layer (models, ORM)	1.5	Normal	needsinfo	modelform instance primary_key update		Unreviewed	0	0	0	0	0	0
