Constant Template Variable, HTML Escaping, and data refresh issues

Hi,

I have written a script that imports pre-built templated Grafana dashboards into my Grafana installation for different orgs. These dashboards make use of template variables, some of which are of type Constant, and others are populated from the Prometheus datasource. As part of the import, the constant template variables are given a pre-set value (specific to the org for which the import job is running). The constant template variables are then used in the dashboard queries to limit scope of the query based on Prometheus labels.

Problem -
One of the constant variables (stack) used in the above scenario, has a valid “EMPTY” state. Since the template variables cannot be empty, I use ‘.+’ instead and the queries use regex match. This works correctly when the dashboard is manually created. However, when the dashboard is imported, while the template variable value shows up correctly (.+) in the template editor, the query sent to Prometheus replaces the ‘+" with an escaped Space (’%20"). This effectively fails the query and returns no data for the dashboard.

see http capture:
https://mydashboard/api/datasources/proxy/8/api/v1/query_range?query=sum(landscape_ec2%7Bapplication%3D%22Digital%20Commerce%22%2Cenvironment%3D~%22%5EProduction.*%22%2Cstack%3D~%22.%20%22%7D)&start=1502741358&end=1502741418&step=1

Strangely, this issue gets temporarily suppressed, if I put the dashboard in edit mode and just randomly tab/click around. Opening the template editor, or the panel editor itself does not make a difference, however seemingly random clicking/tabbing through both the template variable value and anyone of the panel’s query textbox seems to trigger an understanding of the ‘.+’ and prevents the escape. This trigger then applies to all the queries on that dashboard, but only persists until moving out of that dashboard.

see http capture:
https://mydashboard/api/datasources/proxy/8/api/v1/query_range?query=sum(landscape_ec2%7Bapplication%3D%22Digital%20Commerce%22%2Cenvironment%3D~%22%5EProduction.*%22%2Cstack%3D~%22.%2B%22%7D)&start=1502741031&end=1502741091&step=1

One moving out of the dashboard without saving any changes, the situation reverts and opening the dashboard takes it back to the original state.

Obviously I do not want to save the dashboard at this point, as that defeats the purpose of the dashboard import script.

I am using Grafana 4.2.0.

Any ideas on why this is happening?

Never mind.

I figured out that this was being caused because a URL link in one of my dashboards was putting the template variable value without escaping it (thus introducing the issue). This was getting confusing because the template variable values in URL ALWAYS override the values in the Template definition.

However, this brings up the question - Is there any way to prevent URL override of a template variable (any type of variable that CANNOT be overridden by a URL parameter)?

Not there is no way to prevent variables from being set from url