Skip to content

fix(youtube): handle missing title metadata without raising AssertionError - #2238

Merged
Adam Fourney (afourney) merged 3 commits into
microsoft:mainfrom
hsusul:fix-youtube-missing-title-metadata
Sep 3, 2026
Merged

Adam Fourney (afourney) merged 3 commits into
microsoft:mainfrom
hsusul:fix-youtube-missing-title-metadata

Conversation

@hsusul

Copy link
Copy Markdown
Contributor

Summary

  • Prevents YouTubeConverter.convert from raising AssertionError when converting YouTube HTML documents or streams that lack title metadata (title, og:title, name).
  • Allows conversion to proceed gracefully and fall back to the document <title> tag or empty string title.

Problem

When YouTubeConverter.convert() processes a YouTube page or stream that does not contain <meta name="title"> or <meta property="og:title"> tags (such as custom embeds or saved HTML pages), self._get(metadata, ["title", "og:title", "name"]) returns None.

An assertion immediately following this call (assert isinstance(title, str)) caused an unhandled AssertionError to be raised, crashing the conversion of the document.

Root cause

An invalid assert isinstance(title, str) statement was executed directly on the result of self._get(...) before checking if title:. This prevented the converter from reaching its fallback logic at the end of convert().

Fix

Removed the invalid assertion on title. If no meta title tag is present, title remains None, if title: cleanly skips appending the header, and title falls back to soup.title.string or "" at the end of convert().

Testing

  • Added test_youtube_converter_missing_title_metadata to packages/markitdown/tests/test_module_misc.py.
  • Verified that the test fails with AssertionError prior to the fix.
  • Verified that pytest packages/markitdown/tests/test_module_misc.py passes after the fix.

Compatibility

Fully backward-compatible.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An empty <title> element still reaches the remaining assertion with None.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Prevents missing YouTube title metadata from immediately triggering an assertion.

Changes:

  • Removes the premature title assertion.
  • Adds regression coverage for missing and fallback titles.
File summaries
File Description
_youtube_converter.py Allows absent title metadata.
test_module_misc.py Tests missing-title conversion.
Review details

Suppressed comments (1)

packages/markitdown/tests/test_module_misc.py:929

  • Use markdown here as well rather than adding another dependency on the soft-deprecated text_content alias (packages/markitdown/src/markitdown/_base_converter.py:27-35).
        assert "# YouTube" in result_fallback.text_content
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/markitdown/src/markitdown/converters/_youtube_converter.py Outdated
Comment thread packages/markitdown/tests/test_module_misc.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix preserves title fallback behavior and includes adequate regression coverage.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@afourney
Adam Fourney (afourney) merged commit 12b0552 into microsoft:main Sep 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants