django-exclusivebooleanfield
django-exclusivebooleanfield copied to clipboard
Remove mandatory transaction in replaced save method
Fixes #8
Please provide a test case which demonstrates the problem (i.e. a test of the behaviour which you want to work, which fails with the current code)
I need to think more about this... I wanted to ensure that the update of other rows is atomic with the saving of the current instance.
It is my understanding that transaction.atomic supports nesting properly so will not have the problem you describe https://docs.djangoproject.com/en/1.9/topics/db/transactions/#django.db.transaction.atomic ...so we need to fix only for the case of Django < 1.6 using commit_on_success
I am willing to provide the test (I encountered the problem with PostgreSQL, maybe it's even specific to the database system) but in advance I would argue that introducing a mandatory transaction into the save method of all models which use your field is not needed at all. The save calling views and functions are responsible for doing transaction management as fine grained as their authors intend. By introducing the transaction via usage of ExclusiveBooleanField the users of your helpful package have no longer the choice to go without transactions completely, which could be a reasonable choice depending on circumstances for a specific app or project. I would argue that transaction management should be left to the users of your package's field, because as utility app django-execlusivebooleanfield should not make a decision on something like transaction management.
I could introduce an option to disable the transaction (which I guess will be necessary to support Django < 1.6) but I would like the default behaviour to be that it works without introducing unexpected and hard to debug race condition or inconsistent db state. If you want manual transaction handling I think it should be an explicit choice rather than the default.
A possibility to disable it would be a good compromise and would give me the oppurtunity to fix my code where I encountered the issue.