diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

fix: Add type validation to prevent crashes from pipeline signature mismatches (#6969)

Open C1-BA-B1-F3 opened this issue 5 months ago • 0 comments

Description

This PR fixes #6969 by adding type validation to _fetch_class_library_tuple to prevent cryptic crashes when pipeline components have signature mismatches.

Problem

When community pipelines inherit from StableDiffusionPipeline but don't update their __init__ signature to include new parameters like image_encoder, positional arguments can be misaligned. This causes non-module values (like booleans from requires_safety_checker) to be passed where modules are expected, resulting in:

AttributeError: 'bool' object has no attribute '__module__'

Solution

Added validation in _fetch_class_library_tuple to check for __module__ attribute before accessing it. When invalid types are passed, a clear TypeError is raised with actionable guidance:

TypeError: Expected a module or class instance for pipeline component, but received bool: True. 
This is likely due to a signature mismatch in a pipeline's __init__ method. 
If you are using a custom pipeline, please ensure it matches the signature of the base pipeline class. 
For example, if inheriting from StableDiffusionPipeline, ensure your __init__ accepts all parameters 
including 'image_encoder' (added in recent versions).

Testing

  • Added test script test_fix_6969.py that verifies:
    • Valid modules still work correctly
    • Passing bool, int, or str raises TypeError with descriptive message
  • All existing pipeline tests pass (56 passed, 33 skipped)

Impact

This is a minimal, non-breaking change that only affects error handling. Valid modules continue to work as before, while invalid inputs now get a clear, actionable error message instead of a cryptic crash.

Fixes #6969

C1-BA-B1-F3 avatar Jun 25 '26 20:06 C1-BA-B1-F3