Re: [Django] #20742: ModelForm primary_key update with instance set is executed as INSERT caused by is_valid() changing the instance

2013-07-18 Thread Django
#20742: ModelForm primary_key update with instance set is executed as INSERT 
caused
by is_valid() changing the instance
-+-
 Reporter:  amin@…   |Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  1.5
  (models, ORM)  |   Resolution:  needsinfo
 Severity:  Normal   | Triage Stage:
 Keywords:  modelform instance   |  Unreviewed
  primary_key update |  Needs documentation:  0
Has patch:  0|  Patch needs improvement:  0
  Needs tests:  0|UI/UX:  0
Easy pickings:  0|
-+-
Changes (by kmtracey):

 * status:  new => closed
 * resolution:   => needsinfo


Old description:

> 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.
>

> 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='o...@example.com')
>
> form = TestForm(email='n...@example.com', instance=x)
>
> # here instance is updated with n...@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()

New description:

 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='o...@example.com')

 form = TestForm(email='n...@example.com', instance=x)

 # here instance is updated with n...@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()
 }}}

--

Comment:

 A concrete suggestion for what's wanted here would help, as it is I'm not
 sure what's being asked for.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.e541037aa97ffd8f8fa5f6a061027cce%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Django] #20742: ModelForm primary_key update with instance set is executed as INSERT caused by is_valid() changing the instance (was: ModelForm primary_key update with instance set is executed as

2013-07-12 Thread Django
#20742: ModelForm primary_key update with instance set is executed as INSERT 
caused
by is_valid() changing the instance
-+-
 Reporter:  amin@…   |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  1.5
  (models, ORM)  |   Resolution:
 Severity:  Normal   | Triage Stage:
 Keywords:  modelform instance   |  Unreviewed
  primary_key update |  Needs documentation:  0
Has patch:  0|  Patch needs improvement:  0
  Needs tests:  0|UI/UX:  0
Easy pickings:  0|
-+-
Changes (by amin@…):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.58197db9d7a363d1c1302b9c56125ec5%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.