This project is archived and is in readonly mode.

#2492 ✓invalid

BUG: Query Cache does not handle multiple calls to find_or_create_by_*

Reported by findchris | April 14th, 2009 @ 09:33 PM


I came across this bug today in Rails 2.2.2.

Making subsequent calls to a find_or_create_by_* within the lifetime of one request does not behave as expected. The first call is correct, but the second call, because the generated SQL is the exact same, uses the query cache, even if the first call has already created a record. The result is that the second and subsequent calls will create additional records, which is unexpected.

Simple example:

User.find_or_create_by_user_id_and_name(123, "Rails") # Record created here User.find_or_create_by_user_id_and_name(123, "Rails") # Query cache hit; another record created


Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>