#24691: UUIDField sets value before save
-------------------------------+----------------------------
     Reporter:  MattBlack85    |      Owner:  nobody
         Type:  Bug            |     Status:  new
    Component:  Uncategorized  |    Version:  1.8
     Severity:  Normal         |   Keywords:  uuid UUIDField
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+----------------------------
 When using a pk I expect the behaviour we had in the past meaning that
 inside .save() method checking for self.pk gives me a clue of creation vs
 update (documentation confirms that
 https://docs.djangoproject.com/en/1.8/ref/models/instances/#how-django-
 knows-to-update-vs-insert). This is not working when using UUIDField since
 when we enter the save method the pk is already set to the default value.

 to reproduce
 {{{
 import uuid

 from django.db import models

 class AwesomeModel(models.Model):
     id = models.UUIDField(default=uuid.uuid4, primary_key=True)
     x = models.CharField(max_length=10)

     def save(self, *args, **kwargs):
         if self.pk:
             print("we have already a pk set")
         return super(AwesomeModel, self).save(*args, **kwargs)


 a = AwesomeModel(x='some')
 a.save()
 we have already a pk set
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24691>
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/054.ae9bb83fbf9c86f2b3250b9b2ed1b774%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to