Skip to content

Fix mutable default args in lora_base.py#14064

Open
PrakshaaleJain wants to merge 6 commits into
huggingface:mainfrom
PrakshaaleJain:mutable-default-arguments
Open

Fix mutable default args in lora_base.py#14064
PrakshaaleJain wants to merge 6 commits into
huggingface:mainfrom
PrakshaaleJain:mutable-default-arguments

Conversation

@PrakshaaleJain

@PrakshaaleJain PrakshaaleJain commented Jun 25, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes #14052

This PR fixes a bug in src/diffusers/loaders/lora_base.py where a mutable default argument (components: list[str] = []) was used in the signatures of fuse_lora and unfuse_lora. It updates the default value to None and initializes it as a clean, empty list inside the method body if no explicit argument is passed.

Why this change is important:

  1. Prevents Side Effects & State Leakage:
  2. Robustness in Workflows:

Before submitting

Who can review?

Core library / PEFT integrations:

@github-actions github-actions Bot added lora size/S PR with diff < 50 LOC labels Jun 25, 2026

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Do we have an example reproducer reflecting the issue that this PR attempts to solve?

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@PrakshaaleJain

Copy link
Copy Markdown
Author

Hi @sayakpaul!

Although fuse_lora() raises early when components=[], the mutable default argument is still a latent Python bug. Since default arguments are shared across calls, mutating the default list changes the function's default value for the whole Python process.

We can reproduce this directly on the live LoraBaseMixin code using standard reflection without spinning up any pipelines:

import inspect
from diffusers.loaders.lora_base import LoraBaseMixin

sig = inspect.signature(LoraBaseMixin.fuse_lora)
default_object = sig.parameters["components"].default

print(f"Initial default type: {type(default_object)}")  # Expected: <class 'list'>
default_object.append("leaked_state_or_component")

new_sig = inspect.signature(LoraBaseMixin.fuse_lora)
print(f"Mutated default value: {new_sig.parameters['components'].default}") # Expected: ['leaked_state_or_component']
assert len(new_sig.parameters["components"].default) > 0, "Global signature state polluted!"

@github-actions

Copy link
Copy Markdown
Contributor

Hi @PrakshaaleJain, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Fixes #1234) to the PR description so the issue is linked. See the contribution guide for more details. If this PR intentionally does not fix a tracked issue, a maintainer can add the no-issue-needed label to silence this reminder.

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

Labels

fixes-issue lora size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix mutable default argument in lora_base.py

3 participants