mbleigh/acts-as-taggable-on — pull request #499 by jonseaberg (2014-03-23 21:00:09+00:00)
Title: fix for race condition when multiple processes try to add the same tag

It is possible for a site using tags to have multiple web servers and multiple job processes. In this case it is also likely that more than one process could try to add the same tag at the same time. Now that there is a unique index on tag name, no duplicates are created, but a cryptic `ActiveRecord::RecordNotUnique` error makes it up the client code where the taggable was saved. It is hard for the client to know that the `ActiveRecord::RecordNotUnique` must be caught and a simple re save will succeed. This PR is an attempt to make that process easier.

While testing this I found that Postgres and MySQL behave differently when the unique index is violated. Postgres aborts the current transaction, so no more database operations can be executed. For Postgres this means we need to get an exception up to the client. I chose to add an exception to the library so clients can catch and retry their operation. For MySQL we can catch `ActiveRecord::RecordNotUnique` and request the 'duplicates' again.