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

Preserve identifiers when reconstructing a tag which sets a value #988

Merged
merged 6 commits into from
Jan 12, 2023

Conversation

jasmith-hs
Copy link
Contributor

When reconstructing a tag which has the function of setting a variable to the result of an expression (both set and for do this), we should preserve the AstIdentifiers in the expression rather than resolving them because they may be directly referencing a value which can be modified later on. If instead, we set our variable to a serialized version of the object, then if that object is modified, the changes will not be reflected in the set value.

The simplest example of this is shown in one of the new tests:

{% set dict = {} %}

{% set foo = (dict, deferred) %}

{% do dict.update({'a': 'b'}) %}

{{ foo }}

If we don't preserve the identifier for dict, then we end up with:

{% set dict = {} %}

{% set foo = ({}, deferred) %}

{% do dict.update({'a': 'b'}) %}

{{ foo }}

Which would result in foo not having the correct value within it!

I realised that this can also happen if a value is reconstructed and then later one of the elements inside of that value is updated. Such a case is much more difficult to handle. I created a separate issue for that: #987

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

Successfully merging this pull request may close these issues.

1 participant