On Wed, May 13, 2015 at 6:36 AM, Simran Singh <er.simransing...@gmail.com> wrote: > Hi Tom, > > If you see then in if block, I am creating my savepoint. At any point of > time, if the condition is not met and control goes to else block then I want > to rollback all the changes that are saved in transaction and redirect it to > some other page and not commit anything to db. I am able to redirect the > flow to some template but all the transactions are being committed and > rollback functionality is not working. >
Then you don't need savepoints, just abort the transaction by raising an exception. Eg: class UnexpectedNoAssetSpecificationException(Exception): pass class ReservationForm(...): ... def process(self): # asset_port and exclusive_assets are undefined in your sample code # globals are bad for asset in exclusive_assets: inventory = Inventory.objects.filter(asset_id=asset) asset_spec = AssetSpecification.objects.filter( asset_id_id=inventory, utilized_value=0).values_list('asset_id', flat=True) if not assec_spec.count(): raise UnexpectedNoAssetSpecificationException() port_numbers = [ port.port_number for port in asset_port ] AssetPorts.objects.filter( port_number__in=port_numbers).update(usage='Yes') @transaction.atomic def view(request): if request.method == 'POST': form = ReservationForm(request.POST) if form.is_valid(): try: with transaction.atomic(): form.process() except UnexpectedNoAssetSpecificationException: return error(request) return success(request) form = ReservationForm() return render(request, 'reservation.html', { 'form': form, }) I'm interested what is considered "valid" in your form, given this form processing code doesn't seem to access anything from the form. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1LQQRdB6%3DL10-O2Z9eC_j0rEJjynqeitRyP82xvy__c1Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.