Repository navigation
Let the pipeline gate survive a diffusers whose lazy submodule cannot import - #8227
Conversation
… import hasattr absorbs AttributeError and nothing else. diffusers' top level is a lazy module, so the attribute probe is what actually imports the pipeline's submodule, and when that submodule's own dependencies are unsatisfiable it raises RuntimeError, which walks straight out of the guard. That is the same escape the ImportError catch already existed to prevent: not the ValueError the routes map to 400, so it leaves /images/download-plan as a bare 500 with the message lost. A partially usable diffusers install hit it exactly the way a missing one used to. Ten tests were red on main because of it, eight of them in test_video_backend.py. They have been read as an environment problem for a while; they are not.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb86539fca
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| import diffusers | ||
| except ImportError: | ||
| present = hasattr(diffusers, pipeline_class) | ||
| except Exception: # noqa: BLE001 -- see below: this check must never raise anything but its own ValueError |
There was a problem hiding this comment.
Do not accept a pipeline whose lazy import failed
When diffusers imports but resolving the requested pipeline raises RuntimeError because its dependencies are unsatisfiable—the exact case added to the test—this catch now returns success even though the pipeline is unusable. Video has no native fallback: VideoBackend.validate_load_request therefore accepts the model, /video/download-plan advertises its potentially multi-GB files, and /video/load may acquire the GPU and evict the current model before getattr(diffusers, fam.pipeline_class) repeats the same failure in video.py. Convert this lazy-import failure into the route's expected ValueError (while retaining the separate fail-open behavior needed when diffusers is genuinely absent for native image loads), rather than treating it as availability.
Useful? React with 👍 / 👎.
The bug
hasattrabsorbsAttributeErrorand nothing else.diffusers' top level is a lazy module, so inassert_pipeline_class_availablethe attribute probe is what actually imports the pipeline's submodule. When that submodule's own dependencies are unsatisfiable it raisesRuntimeError("Failed to import diffusers.pipelines..."), which walks straight out of the guard.That is precisely the escape the existing
ImportErrorcatch was written to prevent. The docstring already says it: the one thing that must not happen is a raise, because anything other thanValueErroris not what the routes map to 400, so it leaves/images/download-planas a bare 500 with the message lost. A partially usable diffusers install hit that path exactly the way a missing one used to.Effect
Ten tests are red on
mainbecause of it. Same command, same tree, with only this guard swapped:The eight
test_video_backend.pyones have been carried as an environment problem for a while. They are not.Change
Move the attribute probe inside the
tryand widen the catch, so the guard cannot raise anything but its ownValueError. Eight lines, plus a test that fails when either half is reverted.