Rails 3 app has strange behaviour with Mysql2 database

Hi,

I have developed a little web app with a sqlite3 database in development environment. Now I switched over to mysql2 for production environment. At a first look everthing looks good!

BUT, I have delayed_jobs that run methods in the background, where two nested active records were compared with "if hash1 == hash2", then it should just show whether they are the same or not. With mysql2 in production, it shows randomly entries which should have changed, but they didn't! What I found strange is that it is really random!!!

Again with sqlite3 in production or development it is working as intended!!! I checked this in both environments, so that the issues doesn't occur only in production mode. I checked it also with mysql2 in development environment, there I have the same issue that randomly entries were shown that shoould have changed, but didn't in reality.

Finally I think it has something to do with the mysql2 database!!! Has anybody an idea???

My database.yml looks like this: # SQLite version 3.x # gem install sqlite3 production:   adapter: sqlite3   database: db/development.sqlite3   pool: 5   timeout: 5000

# Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test:   adapter: sqlite3   database: db/test.sqlite3   pool: 5   timeout: 5000

development:   adapter: mysql2   encoding: utf8   database: patent_production   pool: 5   username: xxx   password: xxx   host: localhost

I really hope someone can help, because I am searching now for over two days and don't find a solution. I can of course deploy on a sqlite3 db, but I read recommendation to do it rather on mysql.

Cheers, Sebastian

I am using the following code in Check.rb model as a delayed_job. The code runs through every existing entry and looks up if there are new legalevents:

class Check < Struct.new(:id)   def perform     @watchedfamily.watchedmembers.each do |member|         new_legal =         old_legal =         member.legalevents.order("gaz_date").each do |newleg|           new_legal << newleg.attributes.except("id", "created_at", "updated_at", "watchedmember_id")         end         mem = OldWatchedmember.find(:first, :conditions => { :Pub_No => member.Pub_No }).old_legalevents.order("gaz_date")         mem.each do |oldleg|           old_legal << oldleg.attributes.except("id", "created_at", "updated_at", "old_watchedmember_id")         end

        if !(old_legal == new_legal)           @watchedfamily.update_attributes(:has_changed => true)           break         end      end   end end

The code is recognizing when there are new_legal events and is highlighting the changes. But the code also shows me entries that not have been changed, meaning where "old_legal == new_legal" is actually false, but it shows me it is true on random entries. This is working great with sqlite3, but not with mysql2.

I am pretty new to RoR and I don't have a clue why this is happening. Maybe this is because of concurrency and the mysql db has still something in cache that makes the comparing of two equal entries result false...?!?

I really hope that some can give me a hint, how to solve this or isolate the problem!

Sebastian