jpwatts / django-positions

A Django field for custom model ordering.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DoesNotExist error raised by pre_save method if using UUID primary key

hvdklauw opened this issue · comments

Using: Django 1.10, python 3.5 and django-positions 0.5.4

Example model:

import uuid

class Example(models.Model):

    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True)
    parent = models.ForeignKey(SomeOtherModel)
    position = PositionField(null=True, blank=True, collection='parent')

When saving this django will first try an update call because the primary key is already set, which will call the pre_save on the position field with add=False, which will then throw the DoesNotExist error because it tries to load the model from the database which doesn't exist yet.

Maybe it should have a try except in the pre_save to make sure it won't blow up.