Tuesday, October 27, 2015

Re: Locking / serializing access to one element in database

Yes, an exception will be raised. As an example, Django uses force_insert when creating sessions:

https://github.com/django/django/blob/32ef48aa562e6aaee9983f5d0f1c60f02fd555fb/django/contrib/sessions/backends/db.py#L86

On Saturday, October 24, 2015 at 2:36:15 PM UTC-4, Joakim Hove wrote:
Hi Collin;

thank you for your suggestion:

[...] if the thread thinks that the object is new, it could try using .save(force_insert=True). 

I have read to read the force_insert documentation without understanding 100%. Assume threads t1 and t2 are racing to create the first element with this primary key, and that t1 wins the race. Then when t2 issues:
    
    save( force_insert = True )

will an exception be raised?

 

--
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+unsubscribe@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/249303c1-2a39-41a0-8ab9-0d6e4a1bf9fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment