Hello, I'm trying to write an application that will make heavy use of transactions when saving different records to the database. I'm having a problem accessing the data that has been saved within a transaction before I commit the transaction. I need to do this because I need to either save all the entries or fail all the entries. I have written a simple Django app to illustrate my problem. Hopefully someone can give me some help or guidance to resolve this issue.
#model.py class TestModel(models.Model): name = models.CharField(u'name', max_length=35) desc = models.CharField(u'description', max_length=100) class Meta: verbose_name = u'Test' verbose_name_plural = u'tests' def __unicode__(self): return self.name #views.py from django.template import RequestContext from django.db import transaction from dbtest.models import TestModel def runtest(request): transaction.enter_transaction_management() transaction.managed(True) tm = TestModel(name='test1', desc='test1') tm.save() tm = TestModel(name='test2', desc='test2') tm.save() tm = TestModel(name='test3', desc='test3') tm.save() tm = TestModel(name='test4', desc='test4') tm.save() all = TestModel.objects.all() for item in all: x = item.name y = item.desc cnt = TestModel.objects.count() TestModel.objects.get(name='test3').delete() cnt = TestModel.objects.count() all = TestModel.objects.all() for item in all: x = item.name y = item.desc test1 = TestModel.objects.get(name='test1') testList = TestModel.objects.filter(name__gt='name1') if transaction.is_dirty(): transaction.commit() all = TestModel.objects.all() for item in all: x = item.name y = item.desc for item in all: TestModel.objects.get(name=item.name).delete() if transaction.is_dirty(): transaction.commit() return render_to_response('index.html', context_instance=RequestContext(request)) If you run this test you can see my problem. When I try to do an all() or filter() inside of the transaction I get 0 records returned. However, if I do a count() I get the correct number of records for the table. Also, I have a problem that isn't illustrated in this example. If I have a queryset and delete one record within the transaction that record is still returned when all() is called until I commit the transaction. Environment: I am using a Postgres database and have verified that the transactions work as expected from the SQL prompt. My version of Django is SVN trunk. Thanks in advance for you help. Dave --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---