Fix ControlNetUnit copy issue (#2910)

* Fix ControlNetUnit copy issue

* Add copy test
pull/2912/head
Chenlei Hu 2024-05-19 20:41:24 -04:00 committed by GitHub
parent a5c0da5a23
commit b197f7cc41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -471,3 +471,7 @@ class ControlNetUnit(BaseModel):
for (key, value) in (item.strip().split(": "),) for (key, value) in (item.strip().split(": "),)
}, },
) )
def __copy__(self) -> ControlNetUnit:
"""Override the behavior on `copy.copy` calls."""
return self.copy()

View File

@ -1,6 +1,7 @@
import pytest import pytest
import torch import torch
import numpy as np import numpy as np
from copy import copy
from dataclasses import dataclass from dataclasses import dataclass
from internal_controlnet.args import ControlNetUnit from internal_controlnet.args import ControlNetUnit
@ -249,3 +250,11 @@ def test_infotext_parsing():
def test_alias(): def test_alias():
ControlNetUnit.from_dict({"lowvram": True}) ControlNetUnit.from_dict({"lowvram": True})
def test_copy():
unit1 = ControlNetUnit(enabled=True, module="none")
unit2 = copy(unit1)
unit2.enabled = False
assert unit1.enabled
assert not unit2.enabled