#27342: update_or_create example is misleading
     Reporter:  kakarukeys     |      Owner:  nobody
         Type:  Bug            |     Status:  new
    Component:  Documentation  |    Version:  1.10
     Severity:  Normal         |   Keywords:  update_or_create
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  1              |      UI/UX:  0
 In the documentation about update_or_create, the following code

     obj = Person.objects.get(first_name='John', last_name='Lennon')
     for key, value in updated_values.iteritems():
         setattr(obj, key, value)
 except Person.DoesNotExist:
     updated_values.update({'first_name': 'John', 'last_name': 'Lennon'})
     obj = Person(**updated_values)

 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
 whereas, in the latter, John Lennon dictionary is overwritten by

 suggested code change:
 except Person.DoesNotExist:
     new_values = {'first_name': 'John', 'last_name': 'Lennon'}
     obj = Person(**new_values)

Ticket URL: <https://code.djangoproject.com/ticket/27342>
Django <https://code.djangoproject.com/>
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 
For more options, visit https://groups.google.com/d/optout.

Reply via email to