#22571: Document implications of using auto_now_add=True and get_or_create
-------------------------------------+-------------------------------------
     Reporter:  nu.everest@…         |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Documentation        |                  Version:  1.4
     Severity:  Normal               |               Resolution:
     Keywords:  integrityerror       |             Triage Stage:  Accepted
  auto_now_add get_or_create         |
  duplicatekey                       |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by iambibhas):

 * cc: me@… (added)


Comment:

 Replying to [comment:5 charettes]:
 > {{{#!python
 > In [1]: from app.models import Auto, Default, timezone
 >
 > In [2]: added = timezone.now()
 >
 > In [3]: Auto.objects.get_or_create(added=added)
 > Out[3]: (<Auto: Auto object>, True)
 >
 > In [4]: Auto.objects.get_or_create(added=added)
 > Out[4]: (<Auto: Auto object>, True)
 >
 > In [5]: Default.objects.get_or_create(added=added)
 > Out[5]: (<Default: Default object>, True)
 >
 > In [6]: Default.objects.get_or_create(added=added)
 > Out[6]: (<Default: Default object>, False)
 > }}}

 Isn't this expected? The doc says -

 > DateField.auto_now_add
 >
 > Automatically set the field to now when the object is first created.
 Useful for creation of timestamps. Note that the current date is *always*
 used; it’s not just a default value that you can override.

 And the code also shows that the value with always set to `timezone.now()`
 if `auto_now_add` is set, even if you provide a value when creating it.

--
Ticket URL: <https://code.djangoproject.com/ticket/22571#comment:6>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/078.adb5cb5033adafb8cfdad8e69e67d7ca%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to