Liquid rendering is unexpectedly changing the "context" attribute on non-Drop classes
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
Background: I have a Rails app with several classes that are used in Liquid rendering like this:
class Thingy < ApplicationRecord
def to_liquid
LiquidDrops::Thingy.new(record: self)
end
end
module LiquidDrops
class Thingy < Liquid::Drop
attr_accessor :record
def name
record.name
end
end
end
so I can then write {{ my_thingy.name }}, render it with a context like { 'my_thingy' => some_thingy }, and get the right output.
Since upgrading from liquid 5.4.0 to 5.5.0, I've noticed a problem with one of my models that happens to have an attribute named context. Whenever I render some liquid involving that model, it updates the value of context to a Liquid::Context (or a string like "#<Liquid::Context:0x000073767f8c1540>"), even if I'm not doing {{ my_thingy.context }}. This has caused problems where I end up with incorrect values of context in the database.
I suspect this is an unintended side effect of https://github.com/Shopify/liquid/commit/a5e5fab82a8f52f7045c329c15c3663ed25820a0. Would it be possible to limit that change to only set variable.context if variable is a Liquid::Drop, not some arbitrary other type of record?
Thanks for your time!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with commit a5e5fab82a8f52f7045c329c15c3663ed25820a and trace the Liquid rendering path that assigns variable.context. Reproduce the case with a non-Drop object whose attribute is named context, then verify that context is assigned only for Liquid::Drop objects and that the non-Drop value remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100