Skip to content

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

Open
hsusul wants to merge 1 commit into
microsoft:mainfrom
hsusul:fix-youtube-missing-title-metadata
Open

fix(youtube): handle missing title metadata without raising AssertionError#2238
hsusul wants to merge 1 commit into
microsoft:mainfrom
hsusul:fix-youtube-missing-title-metadata

Conversation

@hsusul

@hsusul hsusul commented Jul 25, 2026

Copy link
Copy Markdown

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.

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.

1 participant