Raise on write conflict in save

Jean-Tiare Le Bigot avatarJean-Tiare Le Bigot created an issue

The current way to prevent accidental overwrite of the database item is to provide a set of "expected values". This implies to keep track of the original values on the user model side especially when a migration is involved.

To adress this, we will:

  1. remove the 'expect values' argument
  2. add a "raise on conflict flag" to replace it.

Comments (6)

  1. Éric Araujo

    I just found a use case for the expected_values argument: In a CMS for QA people, I’d like to have a form to edit a challenge object but would like the view to fail, not to retry like a transaction, if the item was edited between GET form and POST change. I was thinking of putting the value in a hidden form field and pass that as expected value in the save call.

  2. Éric Araujo

    Actually, I’m going to do get-change-save, not from_dict-save, so I don’t need the expected_values argument, I’ll do a check before that (just after the get, I’ll check that the field is the same as the hidden form field), so hidden _raw_fields + raise_on_conflict param works for me.

  3. Jean-Tiare Le Bigot

    In the draft implementation, I introduced a ``from_db_dict`` method used internaly by the mapper. Whenever this helper is called, the raw dict is backed-up for the "raise on conflict" feature. It should bring the best of both worlds :)

  4. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.