Given an Active Record relation, ActionController::ConditionalGet#fresh_when calls the relation’s maximum method, which indirectly calls the arel method.
If the same relation is rendered as a cached collection, an ActiveRecord::ImmutableRelation error will be raised:
<%= render partial: 'posts/post', collection: @posts, cached: true %>
ActiveRecord::Railties::CollectionCacheAssociationLoading#relation_from_options checks whether the relation it chooses is loaded before calling ActiveRecord::Relation::QueryMethods#skip_preloading!, but that method can raise ActiveRecord::ImmutableRelation even if the relation isn't loaded (i.e. when ActiveRecord::Relation::QueryMethods#arel was previously called).
This bug was introduced in #31250. A minimal sample application demonstrating it is available here. See the README for a short code walkthrough.
/cc @lsylvester
Given an Active Record relation,
ActionController::ConditionalGet#fresh_whencalls the relation’smaximummethod, which indirectly calls thearelmethod.If the same relation is rendered as a cached collection, an
ActiveRecord::ImmutableRelationerror will be raised:ActiveRecord::Railties::CollectionCacheAssociationLoading#relation_from_optionschecks whether the relation it chooses is loaded before callingActiveRecord::Relation::QueryMethods#skip_preloading!, but that method can raiseActiveRecord::ImmutableRelationeven if the relation isn't loaded (i.e. whenActiveRecord::Relation::QueryMethods#arelwas previously called).This bug was introduced in #31250. A minimal sample application demonstrating it is available here. See the README for a short code walkthrough.
/cc @lsylvester