Mysterious 'duplicate entry' database error when building ta


i tried posting this yesterday, but i never saw my message make it to
the list
so i suspect something went awry…

my rails app has some ‘sync’ code where it connects to a remote db,
grabs the
records from a table, deletes all the records from a table which is a
copy, and then rebuild the table with the records fetched on the remote

it boggles the mind how a duplicate entry error can come up when the
database is confirmed to have no dups in it, the local table gets torn
completely, and rebuilt from scratch. the error only comes up every once
in a
while, so often the code runs fine… here’s the code in question:

begin #rescue block in event remote db is unreachable
homelinks = Syncinventorydesc.find(:all) #fetch all records

InventoryDescription.delete_all() #drop all records from local

for link in homelinks #for each record we fetched…
locallink =

   locallink.inventory_id = link.inventory_id
   locallink.description_id = link.description_id!       #insert into table


since it was just a duplicate entry (no loss of data) i just wrapped
that save
in a rescue block too. the mystery remains however… what happened?

thanks for the assistance!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs