Skip to content

Commit

Permalink
Add a flag for when the context has been prepared by the config's exe…
Browse files Browse the repository at this point in the history
…cution mode already.

This prevents having the meta-context variables get overridden when evaluating an import as it creates a new JinjavaInterpreter based on the current one, which will share the same metaContextVariables set
  • Loading branch information
jasmith-hs committed May 16, 2024
1 parent b5e4e74 commit a77c4e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/hubspot/jinjava/interpret/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public enum Library {
private boolean throwInterpreterErrors = false;
private boolean partialMacroEvaluation = false;
private boolean unwrapRawOverride = false;
private boolean preparedByExecutionMode = false;
private DynamicVariableResolver dynamicVariableResolver = null;
private final Set<String> metaContextVariables; // These variable names aren't tracked in eager execution
private Node currentNode;
Expand Down Expand Up @@ -217,6 +218,7 @@ public Context(
this.deferredExecutionMode = parent.deferredExecutionMode;
this.deferLargeObjects = parent.deferLargeObjects;
this.throwInterpreterErrors = parent.throwInterpreterErrors;
this.preparedByExecutionMode = parent.preparedByExecutionMode;
}
}

Expand Down Expand Up @@ -825,4 +827,12 @@ public void setCurrentNode(final Node currentNode) {
public boolean isInForLoop() {
return get(ForTag.LOOP) != null;
}

boolean isPreparedByExecutionMode() {
return preparedByExecutionMode;
}

void setPreparedByExecutionMode(boolean preparedByExecutionMode) {
this.preparedByExecutionMode = preparedByExecutionMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ public JinjavaInterpreter(
this.context = context;
this.config = renderConfig;
this.application = application;

this.config.getExecutionMode().prepareContext(this.context);
if (!this.context.isPreparedByExecutionMode()) {
this.config.getExecutionMode().prepareContext(this.context);
this.context.setPreparedByExecutionMode(true);
}

switch (config.getRandomNumberGeneratorStrategy()) {
case THREAD_LOCAL:
Expand Down

0 comments on commit a77c4e7

Please sign in to comment.