The problem occurs in many-to-many relations, as in this example
model:

db.define_table('owners', Field('name'))
db.define_table('dogs', Field('name'))
db.define_table(dog_owners',
  Field('owner_id', db.owners),
  Field('dog_id', 'db.dogs'),
  Field('date_owner_got_dog', 'date') #This is important!
)

When an owner record is edited, I would also put on the page a table
of all dogs owned by the owner.  With each dog there is a field for
editing date_owner_got_dog.  The change event for that field triggers
a jQuery script.  The script uses Ajax to tell the server to update
the value.

When an owner record is viewed, I would put up the same table without
capability to edit date_owner_got_dog.

Here is how to get the race condition:
1.  Open an owner record for editing.
2.  Update one of date_owner_got_dog fields.
3.  Quickly click the 'view' link.
4.  Observe old value in the updated field because the server fetched
the dog record before it was updated.

The server can fetch the owner and dog records before finishing the
update triggered by step 2.

I didn't see this in manual testing but Selenium found it right away.

I'm going to put up a 'please wait' flash message before kicking off
the ajax call and change it to a 'done' message when the server has
done its piece.

Anybody have any better ideas?

How does smartgrid handle this?

Reply via email to