Shopify / Shopify/liquid

Possible bug with assign precedence in included partials

Open
#821 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

Given a template that includes another template like so:

{% include 'item' %}

If you then assign a value to the "magic" variable of the template name, a reasonable expectation here would be for the new value to replace the other value.

{% assign item = 'foo' %}
{{ item }}

However, the assign tag in its render method does:

    def render(context)
      val = @from.render(context)
      context.scopes.last[@to] = val
      context.resource_limits.assign_score += assign_score_of(val)
      ''.freeze
    end

And the context.scopes.last means that it has less variable lookup precedence than the template variable and thus will always, in the case of this example be nil.

It seems to me that it should allocate to context.scopes.first as the current active scope? Is this a bug or is there some other logic going on here?

Cheers!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the assign tag's render method shown in the issue, then inspect how context.scopes are populated and resolved for included templates. Reproduce the assign/include example and determine the intended precedence; done means the behavior is settled and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.