<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: validates_uniqueness_of does not guarantee uniqueness</title>
	<atom:link href="http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/feed/" rel="self" type="application/rss+xml" />
	<link>http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/</link>
	<description>Ecchi nanowa ikenai to omoimasu</description>
	<lastBuildDate>Fri, 09 Apr 2010 11:42:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: eno</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/comment-page-1/#comment-9882</link>
		<dc:creator>eno</dc:creator>
		<pubDate>Wed, 04 Mar 2009 17:29:09 +0000</pubDate>
		<guid isPermaLink="false">http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/#comment-9882</guid>
		<description>Hell, no, &quot;A good work around is to use a SELECT FOR UPDATE wrapped in a transaction, which will lock the database.&quot;, is a workaround, and a nonworking at that, because

 * it breaks any login based on transactions (unless you run a database that supports nested transactions) and
 * because it doesn&#039;t work anyways because, erm, it just doesn&#039;t work. Just try it manually in two MySQL consoles in parallel.

what *does* work instead is locking the database, see (if you are interested) the related posts here: http://1rad.wordpress.com/2009/02/23/0x17-atomic-science-revisited/</description>
		<content:encoded><![CDATA[<p>Hell, no, &#8220;A good work around is to use a SELECT FOR UPDATE wrapped in a transaction, which will lock the database.&#8221;, is a workaround, and a nonworking at that, because</p>
<p> * it breaks any login based on transactions (unless you run a database that supports nested transactions) and<br />
 * because it doesn&#8217;t work anyways because, erm, it just doesn&#8217;t work. Just try it manually in two MySQL consoles in parallel.</p>
<p>what *does* work instead is locking the database, see (if you are interested) the related posts here: <a href="http://1rad.wordpress.com/2009/02/23/0x17-atomic-science-revisited/" rel="nofollow">http://1rad.wordpress.com/2009/02/23/0&#215;17-atomic-science-revisited/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hongli</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/comment-page-1/#comment-9637</link>
		<dc:creator>Hongli</dc:creator>
		<pubDate>Tue, 25 Nov 2008 23:59:40 +0000</pubDate>
		<guid isPermaLink="false">http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/#comment-9637</guid>
		<description>Fernando, I never claimed I discovered anything. I merely documented it.</description>
		<content:encoded><![CDATA[<p>Fernando, I never claimed I discovered anything. I merely documented it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fernando</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/comment-page-1/#comment-9636</link>
		<dc:creator>fernando</dc:creator>
		<pubDate>Tue, 25 Nov 2008 23:55:13 +0000</pubDate>
		<guid isPermaLink="false">http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/#comment-9636</guid>
		<description>You didn&#039;t discover anything at all. This race condition is known for a long time. I posted something about it 6 months ago at the following link: http://www.ruby-forum.com/topic/154078

A good work around is to use a SELECT FOR UPDATE wrapped in a transaction, which will lock the database.</description>
		<content:encoded><![CDATA[<p>You didn&#8217;t discover anything at all. This race condition is known for a long time. I posted something about it 6 months ago at the following link: <a href="http://www.ruby-forum.com/topic/154078" rel="nofollow">http://www.ruby-forum.com/topic/154078</a></p>
<p>A good work around is to use a SELECT FOR UPDATE wrapped in a transaction, which will lock the database.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henrik N</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/comment-page-1/#comment-9562</link>
		<dc:creator>Henrik N</dc:creator>
		<pubDate>Wed, 29 Oct 2008 12:52:05 +0000</pubDate>
		<guid isPermaLink="false">http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/#comment-9562</guid>
		<description>This is how I prevent double submits client-side: http://henrik.nyh.se/2008/07/jquery-double-submission</description>
		<content:encoded><![CDATA[<p>This is how I prevent double submits client-side: <a href="http://henrik.nyh.se/2008/07/jquery-double-submission" rel="nofollow">http://henrik.nyh.se/2008/07/jquery-double-submission</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/comment-page-1/#comment-9510</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Wed, 24 Sep 2008 18:34:31 +0000</pubDate>
		<guid isPermaLink="false">http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/#comment-9510</guid>
		<description>Typical Rubyist: If you read my comment, you would see I recommend client-side prevention _in addition to_ backend constraints. On many applications, the client-side component will prevent the vast majority of these problems, making for a much better visitor experience.

As a general rule, it&#039;s a good idea to re-read a comment before you flat out insult it.</description>
		<content:encoded><![CDATA[<p>Typical Rubyist: If you read my comment, you would see I recommend client-side prevention _in addition to_ backend constraints. On many applications, the client-side component will prevent the vast majority of these problems, making for a much better visitor experience.</p>
<p>As a general rule, it&#8217;s a good idea to re-read a comment before you flat out insult it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hongli</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/comment-page-1/#comment-9507</link>
		<dc:creator>Hongli</dc:creator>
		<pubDate>Tue, 23 Sep 2008 16:58:11 +0000</pubDate>
		<guid isPermaLink="false">http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/#comment-9507</guid>
		<description>Typical Rubyist: it isn&#039;t such a bad idea. Of course it shouldn&#039;t be the *only* protection, but when implemented it can drastically reduce the chance of duplicate inserts.</description>
		<content:encoded><![CDATA[<p>Typical Rubyist: it isn&#8217;t such a bad idea. Of course it shouldn&#8217;t be the *only* protection, but when implemented it can drastically reduce the chance of duplicate inserts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Typical Rubyist</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/comment-page-1/#comment-9506</link>
		<dc:creator>Typical Rubyist</dc:creator>
		<pubDate>Tue, 23 Sep 2008 15:40:46 +0000</pubDate>
		<guid isPermaLink="false">http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/#comment-9506</guid>
		<description>Hahaha use JS to disable doubleclicks? Are you serious? If you rely on client, you will lose.</description>
		<content:encoded><![CDATA[<p>Hahaha use JS to disable doubleclicks? Are you serious? If you rely on client, you will lose.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hongli</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/comment-page-1/#comment-9500</link>
		<dc:creator>Hongli</dc:creator>
		<pubDate>Mon, 22 Sep 2008 12:36:02 +0000</pubDate>
		<guid isPermaLink="false">http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/#comment-9500</guid>
		<description>Fjan, transactions doesn&#039;t help you here, even if you use serializable. Try it out for yourself. Unless user 2&#039;s first SELECT statement blocks until user 1&#039;s transaction has been completed (which PostgreSQL doesn&#039;t do), transactions won&#039;t prevent the duplicate insertion.</description>
		<content:encoded><![CDATA[<p>Fjan, transactions doesn&#8217;t help you here, even if you use serializable. Try it out for yourself. Unless user 2&#8242;s first SELECT statement blocks until user 1&#8242;s transaction has been completed (which PostgreSQL doesn&#8217;t do), transactions won&#8217;t prevent the duplicate insertion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fjan</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/comment-page-1/#comment-9499</link>
		<dc:creator>Fjan</dc:creator>
		<pubDate>Mon, 22 Sep 2008 12:25:37 +0000</pubDate>
		<guid isPermaLink="false">http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/#comment-9499</guid>
		<description>I don&#039;t think this is true. By default ActiveRecord wraps all validations inside a transaction for precisely this reason, so as long as you do &quot;the validates_uniqueness_of&quot; inside the model where it belongs there should be no problem. You can try it by adding &#039;BEGIN&#039; and &#039;COMMIT&quot; to your example, the second user should fail.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think this is true. By default ActiveRecord wraps all validations inside a transaction for precisely this reason, so as long as you do &#8220;the validates_uniqueness_of&#8221; inside the model where it belongs there should be no problem. You can try it by adding &#8216;BEGIN&#8217; and &#8216;COMMIT&#8221; to your example, the second user should fail.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manfred</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/comment-page-1/#comment-9497</link>
		<dc:creator>Manfred</dc:creator>
		<pubDate>Mon, 22 Sep 2008 07:36:30 +0000</pubDate>
		<guid isPermaLink="false">http://izumi.plan99.net/blog/index.php/2008/09/20/validates_uniqueness_of-does-not-guarantee-uniqueness/#comment-9497</guid>
		<description>I think you mean &quot;race conditions&quot; instead of &quot;racing conditions&quot;. Nice find though.</description>
		<content:encoded><![CDATA[<p>I think you mean &#8220;race conditions&#8221; instead of &#8220;racing conditions&#8221;. Nice find though.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
