> 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')
Why are you setting save points when all you are doing is running select queries?
I agree with Tom on all his points. Going back to the OP code though:
You have this:
>
> 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.
>
Wouldn't you want this instead?
for portNumber in asset_port:
trans = transaction.savepoint() // Here I am trying not to commit the code and store it in transaction.
AssetPorts.objects.filter(port_number = portNumber.port_number).update(usage='Yes')
You are making a save point *after* the update() operation, meaning that when you roll back later, you're effectively not doing anything because the update() would be part of the previous save point, not the latest one you just stored.
Per the docs: https://docs.djangoproject.com/en/1.8/topics/db/transactions/#django.db.transaction.clean_savepoints
Check out the example just below the section I linked.
You also haven't been explicit about whether or not you only want to roll back the save point during a single iteration of the for loop, or if you want to roll back *all* of the changes that would be implemented by the for loop (or rather, any changes made anywhere in the view).
Apologies if the formatting is off, doing this on my phone.
-James
Did you try changing the position of the save point like I mentioned?
-James
--
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...@googlegroups.com.
To post to this group, send email to django...@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/58a21382-40c5-49b5-b79a-06b289bebd5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.