Different escaping behavior with single and multiple values in templating

Hello everyone. Our team is using Grafana 4.6.3 with Elasticsearch 6.2.0.
We have dashboards with multiple nested variables (group, environment, host etc). By default, the dashboard has only one value selected and when you open the dashboard, it doesn’t escape the query (as you can see on the screenshot below).

After selecting multiple values, the query has proper escaping (see the screenshot below). If you select multiple values and save dashboard, when you open it, the escaping will be like one the second screenshot just from the start.

As you can see, Grafana encloses the query in brackets when using multiple values.

It looks like a bug but the problem is that @torkel wasn’t able reproduce it. Any ideas? For now, I’ve found a workaround in saving dashboard with 2 values selected, so Grafana properly escapes it from the very beginning but I need to know, is this a bug or maybe it’s an expected behavior?

You can find more information regarding this issue here: https://github.com/grafana/grafana/issues/10939