This is slightly heavy-handed as I'm not familiar enough with the AR::Relation's code for a better fix.
Make AR.build_default_scope thread-safe.
Thanks for reporting this. I ended up fixing it in a slightly different way, which is why I haven't accepted this PR. You can see the changes here: 291072a...9ecc443. I also added a test and optimised the performance a bit, when there is no default scope.
Yeah, avoiding touching thread locals unless absolutely necessary is preferable, thanks! :)