Handle duplicate entry errors gracefully [BZ#1112521]