spree/spree — pull request #1504 by alexdowad (2012-05-07 10:46:20+00:00)
Title: Fix for bug which causes duplicate permalinks to be generated under some conditions

To cause Spree to erroneously generate duplicate permalinks:

1. Import a product with name "ABC XYZ". The permalink will be "abc-xyz".
2. Again, import a product with name "ABC XYZ". The permalink will be "abc-xyz-1".
3. Import a product with name "ABC". The permalink will be "abc-2".
4. Again, import a product with name "ABC". The generated permalink will be "abc-2", and validation of the new record will fail with a "duplicate permalink" error.

To prevent this error from occurring, it is necessary to pull back *all* records with matching permalinks in `save_permalink`, from `spree/core/lib/permalinks.rb`. If you just pull back one, I can't see how to guarantee that the generated permalinks will always be unique. There will always be corner cases where it may fail.