{"record":{"id":"e24da9d0f851d295","repo":"tiangolo/fastapi","slug":"number-of-code-include-placeholders-does-not-match","errorCode":null,"errorMessage":"Number of code include placeholders does not match the number of code includes in the original document ({len(code_include_lines)} vs {len(original_includes)})","messagePattern":"Number of code include placeholders does not match the number of code includes in the original document \\((.+?) vs (.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scripts/doc_parsing_utils.py","lineNumber":124,"sourceCode":"    return modified_text\n\n\ndef replace_placeholders_with_code_includes(\n    text: list[str], original_includes: list[CodeIncludeInfo]\n) -> list[str]:\n    \"\"\"\n    Replace code includes placeholders with actual code includes from the original (English) document.\n    Fail if the number of placeholders does not match the number of original includes.\n    \"\"\"\n\n    code_include_lines = [\n        line_no\n        for line_no, line in enumerate(text)\n        if line.strip() == CODE_INCLUDE_PLACEHOLDER\n    ]\n\n    if len(code_include_lines) != len(original_includes):\n        raise ValueError(\n            \"Number of code include placeholders does not match the number of code includes \"\n            \"in the original document \"\n            f\"({len(code_include_lines)} vs {len(original_includes)})\"\n        )\n\n    modified_text = text.copy()\n    for i, line_no in enumerate(code_include_lines):\n        modified_text[line_no] = original_includes[i][\"line\"]\n\n    return modified_text\n\n\n# Header permalinks\n# --------------------------------------------------------------------------------------\n\n\ndef extract_header_permalinks(lines: list[str]) -> list[HeaderPermalinkInfo]:\n    \"\"\"","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/tiangolo/fastapi/blob/3e8d1526d83a90aaf7d6eb6dc682bf150f180b25/scripts/doc_parsing_utils.py#L106-L142","documentation":"Raised by `replace_placeholders_with_code_includes` (scripts/doc_parsing_utils.py:124) as a ValueError when the count of `<CODE_INCLUDE>` placeholders in a translated document does not equal the count of `{* ... *}` code-include directives in the original English document. This is a structural-consistency check used by the docs translation CI: translated docs must preserve the same number of code-include markers so they can be substituted back from the English source.","triggerScenarios":"Running `check_translation` (or the docs CI lint) on a translated markdown file whose translator removed, duplicated, or altered a `{* ... *}` code-include marker. A code include was converted to a real code block or dropped during translation.","commonSituations":"Translators editing code-include lines instead of leaving them verbatim. Partial translations that skipped code sections. A merge that duplicated or removed an include line. The original English doc gained/lost an include and the translation was not regenerated.","solutions":["Restore the exact number of `{* ... *}` code-include lines to match the current English source.","Re-run the translation tooling that injects placeholders from the English doc.","Sync the translation against the latest English document and re-apply the check."],"exampleFix":"// before\n# translated doc has 2 code includes, English has 3\n{* path/a.py *}\n{* path/b.py *}\n// after\n{* path/a.py *}\n{* path/b.py *}\n{* path/c.py *}","handlingStrategy":"validation","validationCode":"from scripts.doc_parsing_utils import extract_code_includes, CODE_INCLUDE_RE\n\ndef code_includes_match(translated_lines, en_lines) -> bool:\n    return len(extract_code_includes(translated_lines)) == len(extract_code_includes(en_lines))","typeGuard":"def translation_has_same_includes(translated_lines, en_lines) -> bool:\n    from scripts.doc_parsing_utils import extract_code_includes\n    return len(extract_code_includes(translated_lines)) == len(extract_code_includes(en_lines))","tryCatchPattern":null,"preventionTips":["Do not edit or remove {* ... *} code-include lines when translating.","Re-run the docs translation check locally before pushing.","Sync translations against the latest English docs before translating new sections."],"tags":["fastapi","docs","translation","ci","validation"],"backgroundTag":null,"analyzedSha":"3e8d1526d83a90aaf7d6eb6dc682bf150f180b25","analyzedAt":"2026-08-11T02:34:52.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}