django-concurrency icon indicating copy to clipboard operation
django-concurrency copied to clipboard

Let IntegerVersionField starts with '1'

Open shintophilip opened this issue 6 years ago • 3 comments

Suppose we have a model,

class User(models.Model):
    version = AutoIncVersionField()

    id = models.UUIDField(primary_key=True, default=uuid.uuid4)
    name = models.CharField(max_length=255)

If we create the object using create, we are getting the expected version value(which is 1).

User.objects.create(name='name')

But instead of that if we create the model using the initializer and create it using the save() method. The version is 2.

user = User(name='name')
user.save()

shintophilip avatar Mar 01 '19 09:03 shintophilip

IntegerVersionField is not what you are looking for. Check AutoIncVersionField. Please consider that you should not add semantic to those values and ignore them, because concurrency is a low level system that should not be exposed to the business logic.

saxix avatar Mar 01 '19 12:03 saxix

Yes. It was a mistake while copying the code. It is AutoIncVersionField.

Agreeing to your point that - concurrency is a low level system that should not be exposed to the business logic. There is no harm in version getting initialized with 2 while creating a model with version with value 2. Thought the expected behavior of AutoIncVersionField is always to increment by 1.

shintophilip avatar Mar 03 '19 06:03 shintophilip

yep, probably is true and I keep this issue opened as enhancement

saxix avatar Mar 28 '19 14:03 saxix