Fix query from template