{"record":{"id":"87d94d9b6d8586e2","repo":"nodejs/node","slug":"extended-multiple-times","errorCode":null,"errorMessage":"extended multiple times","messagePattern":"extended multiple times","errorType":"exception","errorClass":"TemplateRuntimeError","httpStatus":null,"severity":"error","filePath":"tools/inspector_protocol/jinja2/compiler.py","lineNumber":861,"sourceCode":"    def visit_Extends(self, node, frame):\n        \"\"\"Calls the extender.\"\"\"\n        if not frame.toplevel:\n            self.fail('cannot use extend from a non top-level scope',\n                      node.lineno)\n\n        # if the number of extends statements in general is zero so\n        # far, we don't have to add a check if something extended\n        # the template before this one.\n        if self.extends_so_far > 0:\n\n            # if we have a known extends we just add a template runtime\n            # error into the generated code.  We could catch that at compile\n            # time too, but i welcome it not to confuse users by throwing the\n            # same error at different times just \"because we can\".\n            if not self.has_known_extends:\n                self.writeline('if parent_template is not None:')\n                self.indent()\n            self.writeline('raise TemplateRuntimeError(%r)' %\n                           'extended multiple times')\n\n            # if we have a known extends already we don't need that code here\n            # as we know that the template execution will end here.\n            if self.has_known_extends:\n                raise CompilerExit()\n            else:\n                self.outdent()\n\n        self.writeline('parent_template = environment.get_template(', node)\n        self.visit(node.template, frame)\n        self.write(', %r)' % self.name)\n        self.writeline('for name, parent_block in parent_template.'\n                       'blocks.%s():' % dict_item_iter)\n        self.indent()\n        self.writeline('context.blocks.setdefault(name, []).'\n                       'append(parent_block)')\n        self.outdent()","sourceCodeStart":843,"sourceCodeEnd":879,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/inspector_protocol/jinja2/compiler.py#L843-L879","documentation":"Emitted by the compiler when a template contains more than one {% extends %} statement. A template may inherit from at most one parent; the second extends trips an extends_so_far > 0 check. When the parent is statically known the compiler aborts early via CompilerExit; otherwise it emits a runtime TemplateRuntimeError('extended multiple times') into the generated code.","triggerScenarios":"Authoring a template with two {% extends \"x\" %} tags; conditionally including an extends inside a macro/include that itself extends; concatenating template fragments that each carry their own extends.","commonSituations":"Copy-pasting a header (with its extends) into a base template that already extends; building a template dynamically from parts where each part brings an extends; misunderstanding multi-inheritance in Jinja2 (use {% include %} / macros instead).","solutions":["Keep exactly one {% extends %} per template, at the top.","Replace the second inheritance need with {% include %} or macro imports ({% from %} / {% import %}).","If extends must be conditional, use a single {% extends % %} with a computed parent expression rather than multiple extends tags."],"exampleFix":"{# before #}\n{% extends \"base.html\" %}\n{% extends \"other.html\" %}\n{# after #}\n{% extends \"base.html\" %}\n{% from \"other.html\" import extra_block %}","handlingStrategy":"validation","validationCode":"from jinja2 import nodes\ndef count_extends(template_node) -> int:\n    n = 0\n    for stmt in template_node.body:\n        if isinstance(stmt, nodes.Extends):\n            n += 1\n    return n\n# assert count_extends(parsed) <= 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep exactly one {% extends %} per template, at the top.","Use {% include %} / macros / {% import %} for composition instead of multiple extends.","Lint templates in CI to reject duplicate extends tags."],"tags":["jinja2","template","extends","inheritance"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}