This project is archived and is in readonly mode.
BUG: Query Cache does not handle multiple calls to find_or_create_by_*
Reported by findchris | April 14th, 2009 @ 09:33 PM
Greetings.
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
-Chris
Comments and changes to this ticket
-
findchris April 14th, 2009 @ 09:34 PM
Formatting fix:
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
-
CancelProfileIsBroken August 6th, 2009 @ 02:10 PM
- Tag changed from 2.2.2, active_record, cache, find, finder, find_or_create, query, query_cache to 2.2.2, active_record, bugmash, cache, find, finder, find_or_create, query, query_cache
-
Rizwan Reza August 7th, 2009 @ 08:42 PM
not reproducible
I created a test app and checked it. find_or_create_by works as expected.
-
Pratik August 8th, 2009 @ 03:01 AM
- State changed from new to invalid
Works fine for me too.
@findchris Could you please upload a failing test case if this is still an issue ?
Thanks.
-
CancelProfileIsBroken August 8th, 2009 @ 11:06 PM
- Tag changed from 2.2.2, active_record, bugmash, cache, find, finder, find_or_create, query, query_cache to 2.2.2, active_record, cache, find, finder, find_or_create, query, query_cache
- Milestone cleared.
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>