edx/xblock-sdk — pull request #14 by wedaly (2014-06-02 01:13:40+00:00)
Title: Will/fix multiple objects returned

In order to more easily test concurrency issues in ORA2, I've been running workbench with gunicorn and MySQL in repeatable-read mode. Unfortunately, this sometimes causes 500 errors when the workbench persistence layer tries to `get_or_create` an `XBlockState` model in the database. If this method is called in parallel with the database isolation set to repeatable read, each caller will see that no model exists, so they will all try to create one. The end result is that multiple `XBlockState`s exist for the same key, causing the `get_or_create` to raise a `MultipleObjectsReturned` exception.

I've attempted to solve this by:
1) Separating the `get_or_create` call into separate steps, and calling `create` only when setting a field.
2) Redefining `XBlockState` to represent a particular key field and adding a `modified` timestamp.
3) Updating the "get" call to return the `XBlockState` with the most recent `modified` timestamp.

@nedbat and @ormsbee please review.