You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A change was made in ActiveRecord 5.2 such that in addition to the generated AST for a query, the class used to execute that query is cached. The StatementCachegrabs that class via relation.klass which would normally be an ActiveRecord model. However, Octopus wraps the relation in a RelationProxy and that proxy object is the return value of relation.klass.
The next time a query that has a cached statement (e.g. find_by(id:)) the query is executed using that RelationProxy object. This is problematic because that RelationProxy object stores the shard it queried the first time and will send all subsequent queries to that shard.
I have been able to get our test suite to pass by monkey patching StatementCache::create to pull the underlying AR model via relation.klass.klass.klass but I would prefer to find a solution that modifies Octopus instead of ActiveRecord.
We are very late in upgrading to 5.2, I had assumed Octopus was widely used with AR 5.2 and am surprised to have encountered this bug. Is this a known issue for Octopus and is there a recommended workaround?
The text was updated successfully, but these errors were encountered:
A change was made in ActiveRecord 5.2 such that in addition to the generated AST for a query, the class used to execute that query is cached. The
StatementCache
grabs that class viarelation.klass
which would normally be an ActiveRecord model. However, Octopus wraps the relation in aRelationProxy
and that proxy object is the return value ofrelation.klass
.The next time a query that has a cached statement (e.g.
find_by(id:)
) the query is executed using thatRelationProxy
object. This is problematic because thatRelationProxy
object stores the shard it queried the first time and will send all subsequent queries to that shard.I have been able to get our test suite to pass by monkey patching
StatementCache::create
to pull the underlying AR model viarelation.klass.klass.klass
but I would prefer to find a solution that modifies Octopus instead of ActiveRecord.We are very late in upgrading to 5.2, I had assumed Octopus was widely used with AR 5.2 and am surprised to have encountered this bug. Is this a known issue for Octopus and is there a recommended workaround?
The text was updated successfully, but these errors were encountered: