On Tue, May 12, 2015 at 7:47 AM, Simran Singh
<er.simransing...@gmail.com> wrote:
> Thanks Tom for your response. I am attaching piece of code of what I have
> done. I hope this could help.
>
> @transaction.atomic(None, True)
> def reservation(request):
>
>     if request.method == 'POST':
>         reservation_form = ReservationForm(request.POST)
>         if reservation_form.is_valid():
>             for i in xrange(0, len(exclusive_assets)):
>
>                     inventory = Inventory.objects.filter(asset_id =
> exclusive_assets[i])
>                     asset_spec =
> AssetSpecification.objects.filter(asset_id_id=inventory,utilized_value=0).values_list('asset_id',
> flat=True)
>                     trans = transaction.savepoint()  //  Here I am trying
> not to commit the code and store it in transaction.
>
>                     if asset_spec.count():
>                         asset_port = AssetPorts.objects.filter(asset =
> asset_spec,usage='No')
>
>                         for portNumber in asset_port:
>                             AssetPorts.objects.filter(port_number =
> portNumber.port_number).update(usage='Yes')
>                             trans = transaction.savepoint()  //  Here I am
> trying not to commit the code and store it in transaction.
>
>                     else:
>                         transaction.savepoint_rollback(trans) // If any time
> the condition is not met then there should be no update
>
>
>             transaction.savepoint_commit(trans) // Commit changes if all the
> conditions are met
>             return success(request)
>
>
> and in settings file, I have done
> 'default': {
>         'ENGINE': 'django.db.backends.mysql',
>         'NAME': 'lab_on_demand_db',
>         'USER': 'root',
>         'PASSWORD': 'root',
>         'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
>         'PORT': '3306',
>         'AUTOCOMMIT': 'False',
>         }
>
> I am using InnoDB engine with mysql.

I don't understand what you expect this code to do. You make a
savepoint, and if you do nothing to the database, you roll it back.
You only have one statement that modifies your data.

When do you want to rollback, and what do you want it to rollback?

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/CAFHbX1%2BpwYz_SX4Q-wr03KFRScBuqJEp%3D7EQiAhW6GCGhqr7Og%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to