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

Replaced save methods interferes with transaction management

Open leture opened this issue 9 years ago • 0 comments

The following simple example (Django 1.4) shows how the replaced save function of models with ExclusiveBooleanField can led to data saved in the database which were not meant to end up there:

def function():
    with transaction.commit_on_succes():
        # Part 1: does some stuff which changes database
        instanceOfModelWithExclusiveBooleanField.save()
        # Part 2: throws an exception

The with transaction.commit_on_succes() block is meant to group stuff which should end up all together or nothing of it in the database. A call of save to a model with ExclusiveBooleanField in the middle breaks this assumption because in the replaced save function commit_on_success is used which would commit the open transaction. In the example everything of Part 1 one will be in the database regardless if an exception is thrown in Part 2 or not.

leture avatar Jan 12 '16 21:01 leture