Murray Steele
2009-Jan-05 13:47 UTC
[PATCH] Fix for obscure bug with eager-loading and nested includes
Hi all, Here''s a patch for fixing a bug with nested includes and missing data when you use the old-style single query eager loading. http://rails.lighthouseapp.com/projects/8994/tickets/1696 It''s a fairly obscure bug; we only saw it in a live 1.2.6 app after it''d been out for about a year and with 2.x''s multi-query eager loading for most cases it''s even less likely to occur, but it''s a bug none-the-less. What it boils down to is: doing a find with 3 nested includes where the first include has no data will cause a NoMethodError. The problem is that JoinDependency uses 2 arrays (associaitons and joins) to interrogate rows of data and assumes they never get out of sync, which in this case, they do. The fix is to find the correct join in the second array for the association we are constructing, rather than just using the first join in the array. I''d appreciate some more eyes on it as I''m not hugely convinced that the test case is complete / expressive enough. Cheers, Muz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Jan-05 14:27 UTC
Re: [PATCH] Fix for obscure bug with eager-loading and nested includes
On 5 Jan 2009, at 13:47, Murray Steele wrote:> Hi all, > > Here''s a patch for fixing a bug with nested includes and missing > data when you use the old-style single query eager loading. > > http://rails.lighthouseapp.com/projects/8994/tickets/1696 > > It''s a fairly obscure bug; we only saw it in a live 1.2.6 app after > it''d been out for about a year and with 2.x''s multi-query eager > loading for most cases it''s even less likely to occur, but it''s a > bug none-the-less. What it boils down to is: doing a find with 3 > nested includes where the first include has no data will cause a > NoMethodError. The problem is that JoinDependency uses 2 arrays > (associaitons and joins) to interrogate rows of data and assumes > they never get out of sync, which in this case, they do. The fix is > to find the correct join in the second array for the association we > are constructing, rather than just using the first join in the array. > > I''d appreciate some more eyes on it as I''m not hugely convinced that > the test case is complete / expressive enough. >Ah JoinDependency, my least favourite bit of rails :-) I''ll have a look at this one. Fred> Cheers, > > Muz > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---