﻿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
34933	update_or_create() does not persist field changes in save() when performing an update	Crispin Ali Basah	nobody	"It seems when ''update_or_create()'' is updating an object, field updates set in the model's overriden ''save()'' method is not persisted in the database.

The following simple model illustrates this behavior. ''field1'' is set via the ''default={...}'' argument while ''field2'' is an increment of ''field1'' by 1 performed in the model's overridden ''save()'' method.

{{{#!python
class Test(models.Model):
    field1 = models.PositiveSmallIntegerField(blank=True, null=True)
    field2 = models.PositiveSmallIntegerField(blank=True, null=True)

    def save(self, *args, **kwargs):
        self.field2 = self.field1 + 1
        super().save(*args, **kwargs)
}}}

The following call for ''update_or_create()'' '''inserts''' the object with id 1
{{{#!python
>>> (obj, is_created) = Test.objects.update_or_create(id=1, defaults={'field1': 1})
>>> Test.objects.get(id=1).field1
1
>>> Test.objects.get(id=1).field2
2
}}}

The following call '''updates''' the same object
{{{#!python
>>> (obj, is_created) = Test.objects.update_or_create(id=1, defaults={'field1': 10})
>>> Test.objects.get(id=1).field1
10
>>> Test.objects.get(id=1).field2
2
}}}
However, field2 does not get updated to 11.

"	Bug	closed	Database layer (models, ORM)	4.2	Normal	duplicate	update_or_create		Unreviewed	0	0	0	0	0	0
