Skip to content

Explicitly disable Mustache partials#138944

Merged
joegallo merged 9 commits intoelastic:mainfrom
joegallo:mustache-tests
Dec 3, 2025
Merged

Explicitly disable Mustache partials#138944
joegallo merged 9 commits intoelastic:mainfrom
joegallo:mustache-tests

Conversation

@joegallo
Copy link
Contributor

@joegallo joegallo commented Dec 2, 2025

They're already documented as being unsupported, this just makes them be unsupported more officially by rejecting them in the template compilation rather than 'merely' having it not work. This allows us to have a better error message.

In preparation for upgrading to mustache.java 0.9.14, I also expanded two test exception message regexes to be more accepting. That'll help me on the BWC test side of the house on #138923.

Note: I intend to backport this pretty widely, but I haven't completely figured out the destinations for it just yet.

@joegallo joegallo requested a review from rjernst December 2, 2025 22:17
@joegallo joegallo requested a review from a team as a code owner December 2, 2025 22:17
@joegallo joegallo added >non-issue :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache auto-backport Automatically create backport pull requests when merged v9.3.0 labels Dec 2, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Dec 2, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one suggestion.

public void partial(TemplateContext tc, String variable, String indent) {
// throwing a mustache exception here is important because this gets caught, handled (closing readers, etc),
// and re-thrown in the mustache parser itself
throw new MustacheException("partial templates are not supported");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the exception message contain the variable name for additional context? Something like Cannot expand 'foobar' because partial templates are not supported

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, I went with a very slightly different error message in 4b6a643, but if you like your wording more than mine, I don't mind switching it out. I wanted to more closely match the not found message that mustache emitted on its own (see f865be0), but that doesn't have to be a priority.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think "not found" is a little confusing because it's not that if we "found" it we would support it, it's that we don't support these at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I'll make it like you had originally suggested.

@joegallo
Copy link
Contributor Author

joegallo commented Dec 3, 2025

I can't get CI to pass because of some ESQL failures, so I'm merging in main and throwing away all my green builds. We'll see if that improves things. 🤷

@joegallo joegallo merged commit 42c2aa2 into elastic:main Dec 3, 2025
35 checks passed
@joegallo joegallo deleted the mustache-tests branch December 3, 2025 19:43
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
9.1
8.19
9.2
joegallo added a commit to joegallo/elasticsearch that referenced this pull request Dec 3, 2025
joegallo added a commit to joegallo/elasticsearch that referenced this pull request Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >non-issue Team:Core/Infra Meta label for core/infra team v8.19.9 v9.1.9 v9.2.3 v9.3.0

3 participants