Fix loose of templates on cloned query

This pull request fixes the problem reports on #1071