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
It seems that the process of rendering is deleting the :view key from the options hash. This breaks batching as only the first batch can be rendered correctly with subsequent ones falling back to the default view.
Expected Behavior
Options k-v pairs should persist through to subsequent batch renders.
Steps To Reproduce
Given this blueprint:
class FooBlueprint < ApplicationBlueprint
identifier :id
view :with_bar_id do
field :bar_id
end
end
This code:
options = { a_key: 'a value', view: :with_bar_id }
prerendered_foos = []
Foo.limit(5).in_batches(of: 2) do |batch|
prerendered_foos += FooBlueprint.render_as_hash(batch, options)
end
FWIW this looks like a good candidate to me, although it's five years old. But if your options hash is newly being shared across multiple renders, it seems a likely cause.
Ah, apologies, I was mistaken that this was working before; I discovered this during a refactor and I got my wires crossed. The code that @jhollinger references above is indeed the issue, so this is perhaps more of a 'feature request'.
I have this draft PR (currently without tests) to start the conversation about what a possible 'fix' for this could look like if we agree this is a good idea. I'm not really sure why the existing uses delete but perhaps someone has a good reason.
I have also edited the above to better illustrate this issue.
Is there an existing issue for this?
Is this a regression?
Current Behavior
It seems that the process of rendering is deleting the
:view
key from the options hash. This breaks batching as only the first batch can be rendered correctly with subsequent ones falling back to the default view.Expected Behavior
Options k-v pairs should persist through to subsequent batch renders.
Steps To Reproduce
Given this blueprint:
This code:
generates this as
prerendered_foos
:The rendering of the first batch deletes the view option and the subsequent batches fall back to the default identifier-only view.
The workaround I am currently using is to re-add the view to the options hash after every batch, but this is unsatisfactory.
Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: