niwibe/django-orm — Issue #3: Postgresql FTS manager's update_index commits current transaction when it shouldn't
Author: nigma
Created: 2012-01-19 15:14:24+00:00
State: open

There's a `COMMIT` statement in the `SearchManagerMixIn.update_index` that is executed regardless of the transaction management state and simply commits current transaction:

https://github.com/niwibe/django-orm/blob/9b35303d392958a253fda8424e1446f4e0cb4782/django_orm/postgresql/fts/mixin.py#L68

I'm not sure but it probably should be replaced with something like `transaction.commit_unless_managed()`.

Example of incorrect behavior:

```python
from django.db import transaction

p = Profile.objects.get(pk=1)
p.about = "old value"
p.save()

with transaction.commit_on_success():
p = Profile.objects.get(pk=1)
p.about = "this shouldn't be committed"
Article.objects.update_index(pk=1)
p = Profile.objects.get(pk=1)
print p.about
raise Exception()

# The value of the about field should remain unchanged
p = Profile.objects.get(pk=1)
print p.about
```

This occurs with and without autocommit turned on.