Intermittent problem finding records - ever seen this?

I seem to remember this from a very long time ago. I believe that what’s happening is that in this line

pickup_address = Address.find(item.pickup_location)

item.pickup_location is nil. and nil.id == 4 If you change it to

pickup_address = Address.find( :first, item.pickup_location )

Out of curiosity, what is item.pickup_location? Is it an address?

If it is, just use pickup_address = item.pickup_location

anyway. Hopefully that’s on the right track.

Hi Daniel, thanks for the response. None of my Items have a missing pickup_address (it just happens to error on address #4 a lot, but also #5 and #26.) :slight_smile:

>>Out of curiosity, what is item.pickup_location? Is it an address?

item.pickup_location is an address.id. This was my first Rails app and I when I started writing it, I never set up has_many / belongs_to relationship between Item and Address. Thought about trying that here to see if it would fix things, but I really wanted to figure out the root problem to what I'm seeing. It's really puzzling me!

I've combed the forum archives but haven't seen anything similar.

Hmm.. I'm guessing: #1 -- There's a bug in your app.

Dig out the query from an exception trace or your logs, ensure sure it makes sense and returns what you expect when run from psql.

#2 -- Hardware issues

Likely to cause intermittent errors. Should be plenty of resources for diagnosing this sort of thing on google, I think.

Perhaps you could write something automated that repeatedly dumps the db (or a copy if you can't take it offline), then compress and finally md5sum the output.

Try reinstalling/upgrading pg if the hash changes while your data doesn't, then talk to the hosting co when there are still issues.

#3 -- Something weird in your rails/ruby/ruby<->postgres driver/postgres install or configuration.

Ouch. No idea..

Good luck, Isak