﻿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
24691	Document model._state.adding (since UUIDField sets value before save)	Mattia Procopio	nobody	"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
}}}

"	Cleanup/optimization	closed	Documentation	1.8	Normal	duplicate	uuid UUIDField		Accepted	0	0	0	0	0	0
