Wednesday, November 26, 2014

Re: Preventing race conditions when submitting forms

Hi,

On websites where there's a lot of editing happening, I've been trying to minimize the number of fields available on a page for editing. Ideally only the data that changed in the UI even get sent to the server. That way there's less chance of a conflict happening in the first place.

Collin

On Tuesday, November 25, 2014 10:57:08 AM UTC-5, Paul Johnston wrote:
Hi,

Consider an e-commerce site, where Alice and Bob are both editing the product listings. Alice is improving descriptions, while Bob is updating prices. They start editing the Acme Wonder Widget at the same time. Bob finishes first and saves the product with the new price. Alice takes a bit longer to update the description, and when she finishes, she saves the product with her new description. Unfortunately, she also overwrites the price with the old price, which was not intended.

It's worth noting that the controller methods are thread-safe in themselves. They use database transactions, which make them safe in the sense that if Alice and Bob try to save at the precise same moment, it won't cause corruption. The race condition arises from Alice or Bob having stale data in their browser.

Does Django have any way to prevent these race conditions? Just rejecting the second edit with an "edit conflict" message would be a start - although some intelligent merging would be even better.

Thanks,

Paul

--
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/4acc27fc-917e-4c2a-8bf2-7bf58637671a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment