Variable value not replaced in query

On some timeseries panels, I add horizontal lines whose Y value is a variable. The trick is essentially to multiply a timeseries which I know will always have data points by 0, then add the variable as a constant.

The image below was created using this method, so I’m positive that it works.

The query looks essentially like:

SELECT "timeseries_that_has_values" * 0 + $Variable
FROM "data_source" 
WHERE ("foo" = 'bar') 
AND $timeFilter

If I replace $Variable by, say, 1, I get this:

Again, it works.
If I check the variable value, there it is:

But if I use it in the query, I get an error:
“error parsing query: found FROM, expected identifier, string, number, bool at line 1, char 43”

Upon investigation, this is the query sent, which understandably yields the error above:

2022-01-26 19_32_27-Template - Ops Dashboard - Grafana and 1 more page - Work - Microsoft​ Edge

If you look closely, the variable value is simply not inserted in the query after the “+”

Any thoughts on what could be going on?

And a remark: what’s even more confusing to me is that sometimes it just works

See the -99 where it should be

2022-01-26 19_43_13-