Hi,

Le Tue, 22 Jan 2008 11:07:45 -0800 (PST), "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> a écrit :

> Example:
> Processes P1, P2, model instance m, with m.val
> 
> - P1 grabs the object : m = MyModel.objects.filter(get the m i want)
> [0]
> - P2 grabs the object : m = MyModel.objects.filter(get the m i want)
> [0]
> - P1 m.val += 1
> - P2 m.val += 1
> - P1 m.save()
> - P2 m.save()
> 
> What happens normally? What happens with the transaction middleware?

I guess the save() methods will set directly the new value, instead of
sending a "val + 1" UPDATE to the database.

So, if m.val == 0 when you load the object in both P1 and P2, it will
result in :

  UPDATE mymodel SET val = 1 WHERE id = ?

whereas you want :

  UPDATE mymodel SET val = val + 1 WHERE id = ?

In the latter, the transaction will handle this (well, as Jeff Anderson
said, the _database_ will handle this), and your "val" field will be +2.

However, I'm pretty sure Django will do the former. It needs to be
checked.
But, I guess you can add a method (or override the save() method
maybe), to send the correct SQL query.

 - Jonathan

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to