Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquid rendering is unexpectedly changing the "context" attribute on non-Drop classes #1794

Open
lavaturtle opened this issue Apr 15, 2024 · 0 comments

Comments

@lavaturtle
Copy link

lavaturtle commented Apr 15, 2024

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 a5e5fab. 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant