Fix for #22232 preventing RuntimeError Maximum Recursion Depth Exceeded when a template extends itself