Skip to content

fix: lazy imports to prevent torchcodec FFmpeg DLL crash on Windows#1092

Merged
VinciGit00 merged 1 commit into
mainfrom
fix/torchcodec-ffmpeg-crash-main
Jun 23, 2026
Merged

fix: lazy imports to prevent torchcodec FFmpeg DLL crash on Windows#1092
VinciGit00 merged 1 commit into
mainfrom
fix/torchcodec-ffmpeg-crash-main

Conversation

@VinciGit00

Copy link
Copy Markdown
Member

Backports #1089 (merged into pre/beta) to main.

Description

On Windows systems without FFmpeg native DLLs, importing BaseLoader from langchain_community.document_loaders.base triggers the sentence_transformerstorchcodec → FFmpeg loading chain, which crashes with a DLL load error.

This PR fixes it via lazy imports:

  1. Remove BaseLoader inheritance from ChromiumLoader (reimplements load()/aload())
  2. Lazy __getattr__ in docloaders/__init__.py for ChromiumLoader/PlasmateLoader
  3. Move PyPDFLoader and AsyncChromiumLoader imports into function bodies
  4. Mock torchcodec in tests/conftest.py to prevent the crash during test import

Notes

🤖 Generated with Claude Code

…1089)

Remove BaseLoader inheritance from ChromiumLoader and use lazy imports
for PyPDFLoader and AsyncChromiumLoader to avoid triggering the
sentence_transformers -> torchcodec -> FFmpeg native DLL loading chain
at import time, which crashes on systems where FFmpeg DLLs are not
available.

Also add torchcodec mock to conftest.py for the test suite.

Changes:
- chromium.py: remove BaseLoader import/inheritance, add load()/aload()
- docloaders/__init__.py: lazy __getattr__ for ChromiumLoader, PlasmateLoader
- fetch_node.py: lazy PyPDFLoader import
- robots_node.py: lazy AsyncChromiumLoader import
- conftest.py: torchcodec module mock
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jun 23, 2026
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 43a1671.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@VinciGit00 VinciGit00 merged commit e5c2a42 into main Jun 23, 2026
5 of 6 checks passed
github-actions Bot pushed a commit that referenced this pull request Jun 23, 2026
## [2.1.4](v2.1.3...v2.1.4) (2026-06-23)

### Bug Fixes

* lazy imports to prevent torchcodec FFmpeg DLL crash on Windows ([#1089](#1089)) ([#1092](#1092)) ([e5c2a42](e5c2a42))

### Docs

* swap Integrations infographic for new API banner; fix CTA links ([71ab440](71ab440))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working released on @stable size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants