tiangolo/fastapi · error · RuntimeError
Couldn't auto-generate sponsors section
Error message
Couldn't auto-generate sponsors section
What it means
Raised by generate_readme_content() in scripts/docs.py:357 when it cannot locate the sponsor placeholder markers in docs/en/docs/index.md. The README is generated by slicing index.md between the markers '<!-- sponsors -->' and '<!-- /sponsors -->' (scripts/docs.py:352-353) and injecting rendered sponsor HTML. If either marker is absent the slice boundaries are undefined, so the function aborts rather than emit a malformed README.
Source
Thrown at scripts/docs.py:357
match = header_with_permalink_pattern.match(line)
if match:
hashes, title, *_ = match.groups()
line = f"{hashes} {title}"
lines.append(line)
return "\n".join(lines)
def generate_readme_content() -> str:
en_index = en_docs_path / "docs" / "index.md"
content = en_index.read_text("utf-8")
content = remove_header_permalinks(content) # remove permalinks from headers
match_pre = re.search(r"</style>\n\n", content)
match_start = re.search(r"<!-- sponsors -->", content)
match_end = re.search(r"<!-- /sponsors -->", content)
sponsors_data_path = en_docs_path / "data" / "sponsors.yml"
sponsors = yaml.safe_load(sponsors_data_path.read_text(encoding="utf-8"))
if not (match_start and match_end):
raise RuntimeError("Couldn't auto-generate sponsors section")
if not match_pre:
raise RuntimeError("Couldn't find pre section (<style>) in index.md")
frontmatter_end = match_pre.end()
pre_end = match_start.end()
post_start = match_end.start()
template = Template(index_sponsors_template)
message = template.render(sponsors=sponsors, sponsor_img_url=sponsor_img_url)
pre_content = content[frontmatter_end:pre_end]
post_content = content[post_start:]
new_content = pre_content + message + post_content
# Remove content between <!-- only-mkdocs --> and <!-- /only-mkdocs -->
new_content = re.sub(
r"<!-- only-mkdocs -->.*?<!-- /only-mkdocs -->",
"",
new_content,
flags=re.DOTALL,
)
return new_contentView on GitHub (pinned to 3e8d1526d8)
Solutions
- Open docs/en/docs/index.md and confirm both '<!-- sponsors -->' and '<!-- /sponsors -->' are present exactly as written.
- Restore the markers from git history: git log -p -- docs/en/docs/index.md | grep -n 'sponsors'.
- Re-run generate-readme once both markers exist.
Example fix
<!-- before: markers missing --> ## FastAPI ... <!-- after: restore both markers --> ## FastAPI <!-- sponsors --> <!-- /sponsors -->
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
def has_sponsor_markers(index_md: Path) -> bool:
text = index_md.read_text(encoding="utf-8")
return "<!-- sponsors -->" in text and "<!-- /sponsors -->" in text Try / catch
try:
content = generate_readme_content()
except RuntimeError as e:
if "sponsors" in str(e):
raise RuntimeError("index.md is missing sponsor markers; restore them") from e
raise Prevention
- Treat the sponsor HTML comment markers as load-bearing; never delete them in index.md.
- Add a CI grep assertion for both markers before generate-readme.
- Code-review edits to index.md front matter and sponsor block.
When it happens
Trigger: Running `python scripts/docs.py generate-readme` (or any workflow calling generate_readme_content) after the sponsor markers were removed or renamed in docs/en/docs/index.md. Fires when match_start or match_end is falsy at scripts/docs.py:356.
Common situations: Someone edited index.md and deleted/renamed the sponsor HTML comment markers. A find-and-replace rewrote HTML comments. The index.md file was regenerated from a template that omits the markers.
Related errors
- Couldn't find pre section (<style>) in index.md
- Code block (lines {start_line}-{end_line_no}) has different
- Number of code blocks does not match the number in the origi
- {release_notes_file} must start with {RELEASE_NOTES_HEADER!r
- {release_notes_file} must start with {latest_header!r}
AI-assisted analysis of tiangolo/fastapi@3e8d1526d8 (2026-08-11).
Data as JSON: /api/errors/a8cfcccbfe22a12e.
Report an issue: GitHub.