﻿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
27342	"QuerySet.update_or_create() ""shortcut to boilerplatish code"" example is incorrect"	kakarukeys	Tim Graham	"In the documentation about update_or_create, the following code

{{{
try:
    obj = Person.objects.get(first_name='John', last_name='Lennon')
    for key, value in updated_values.iteritems():
        setattr(obj, key, value)
    obj.save()
except Person.DoesNotExist:
    updated_values.update({'first_name': 'John', 'last_name': 'Lennon'})
    obj = Person(**updated_values)
    obj.save()
}}}

is said to be practically the same as:
{{{
obj, created = Person.objects.update_or_create(
    first_name='John', last_name='Lennon', defaults=updated_values)
}}}

however, in the former, updated_values is overwritten by John Lennon dictionary.
whereas, in the latter, John Lennon dictionary is overwritten by update_values.

suggested code change:
{{{
except Person.DoesNotExist:
    new_values = {'first_name': 'John', 'last_name': 'Lennon'}    
    new_values.update(updated_values)
    obj = Person(**new_values)
    obj.save()
}}}
"	Bug	closed	Documentation	1.10	Normal	fixed	update_or_create		Accepted	1	0	0	0	1	0
