liqd / adhocracy

Adhocracy is a policy drafting and decision making software for distributed groups and open institutions.
GNU Affero General Public License v3.0
150 stars 37 forks source link

It is possible to create user badge assignments multiple times #921

Open nidico opened 10 years ago

nidico commented 10 years ago

If users double-click on submit in the user badge form, they may create user (and probably others too) badge assignments multiple times. Afterwards this badge can't be deleted anymore, as SQLAlchemy will then complain:

WebApp Error: <class 'sqlalchemy.orm.exc.StaleDataError'>: DELETE statement on table 'user_badges' expected to delete 1 row(s); Only 3 were matched.

How to fix? Possibilities:

  1. Not allow double clicks through Javascript. This is useful in other submits as well (comments etc.). It doesn't prevent that issue from happening if users want to force it.
  2. Add UNIQUE constraints to the xx_badges tables. This avoids that multiple processes add badges concurrently.
  3. Deal with it, i.e. accept that badges exist multiple times. Make sure all of them are deleted when they're supposed to. This might not be easily possible without changing the ORM configuration.

If (3) isn't realized, the existing problems need to be fixed on database level manually.

xi commented 10 years ago

Option (1) has been implemented in #925. I would like (3) to be implemented so I will leave this open.