Worrying MySQL behaviour -- unlogged insert. Bug?

Had a bug on my production server last night that I've managed to track down. Only prob is the cause makes me a bit nervous. I've got a postcode model where the code attribute must be unique (checked with validates_uniqueness_of). OK. No prob there. However I got an error where there shouldn't have been one, because a postcode (just one) was showing as invalid -- because it had a duplicate code.

I check the MySQL table and sure enough there's a duplicate code -- the records with ids 6783 and 6784 were the same, and both created at the same time.

OK, so how come there was a duplicate code in there? Checked the logs, and this gets even more strange. I see where 6782 is inserted, and I see where 6784 is inserted (or at least where the validation occurs which references 6784 occurs), but no 6783. There's only one insertion.

So where's the prob occurring. In the code or Rails (unlikely, as I would think it would be in the logs). In the MySQL adapter. In MySQL?

Anyone got any ideas?

TIA Chris

    e[4;36;1mPostcode Load (0.016900)e[0m e[0;1mSELECT * FROM     postcodes WHERE (postcodes.`code` = 'SA659TL' ) LIMIT 1e[0m     e[4;35;1mSQL (0.000420)e[0m e[0mBEGINe[0m     e[4;36;1mPostcode Load (0.013744)e[0m e[0;1mSELECT * FROM     postcodes WHERE (postcodes.code = 'SA659TL') LIMIT 1e[0m     e[4;35;1mSQL (0.000590)e[0m e[0mINSERT INTO postcodes (`latitude`,     `updated_at`, `code`, `longitude`, `created_at`)     VALUES(51.9614153479851, '2006-10-19 23:03:26', 'SA659TL',     -4.91567909471854, '2006-10-19 23:03:26')e[0m     e[4;36;1mSQL (0.017815)e[0m e[0;1mCOMMITe[0m     *e[4;35;1mPostcode Load (0.017902)e[0m e[0mSELECT * FROM postcodes     WHERE (postcodes.code = 'SA659TL' AND postcodes.id <> 6782) LIMIT 1e[0m     *e[4;36;1mSQL (0.000465)e[0m e[0;1mBEGINe[0m     e[4;35;1mItem Load (0.001294)e[0m e[0mSELECT * FROM items WHERE     (items.item_details_id = 30277 AND items.item_details_type = 'Hse')     LIMIT 1e[0m     e[4;36;1mHseProhibition Load (0.662752)e[0m e[0;1mSELECT * FROM     hses WHERE (hses.notice_id = 'F110005093' AND hses.notice_type =     'Immediate Prohibition Notice' AND hses.id <> 30277) AND (     (hses.`type` = 'HseProhibition' ) ) LIMIT 1e[0m     e[4;35;1mSQL (0.044114)e[0m e[0mINSERT INTO items (`updated_at`,     `item_details_type`, `item_details_id`, `created_at`, `geom`)     VALUES('2006-10-19 23:03:27', 'Hse', 30277, '2006-10-19 23:03:27',     GeomFromWKB(0x0101000000BEC9D5C7A7A913C0F7BB7AA80FFB4940,-1))e[0m     e[4;36;1mSQL (0.000524)e[0m e[0;1mCOMMITe[0m     e[4;35;1mPostcode Load (0.160674)e[0m e[0mSELECT * FROM postcodes     WHERE (postcodes.`code` = 'SA147NU' ) LIMIT 1e[0m     e[4;36;1mSQL (0.006116)e[0m e[0;1mBEGINe[0m     e[4;35;1mPostcode Load (0.063651)e[0m e[0mSELECT * FROM postcodes     WHERE (postcodes.code = 'SA147NU') LIMIT 1e[0m     e[4;36;1mSQL (0.001712)e[0m e[0;1mINSERT INTO postcodes     (`latitude`, `updated_at`, `code`, `longitude`, `created_at`)     VALUES(51.79958969985, '2006-10-19 23:03:28', 'SA147NU',     -4.05398086378695, '2006-10-19 23:03:28')e[0m     e[4;35;1mSQL (0.004157)e[0m e[0mCOMMITe[0m     *e[4;36;1mPostcode Load (0.033487)e[0m e[0;1mSELECT * FROM     postcodes WHERE (postcodes.code = 'SA147NU' AND postcodes.id <>     6784) LIMIT 1e[0m*