From fd53f3884144555654d428caf7a144de30d9d275 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:33:08 +1000 Subject: [PATCH] fix(nodes): return copies of objects in invocation ctx Closes #6820 --- invokeai/app/services/shared/invocation_context.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/invokeai/app/services/shared/invocation_context.py b/invokeai/app/services/shared/invocation_context.py index bf7f9892359..971fcd4b594 100644 --- a/invokeai/app/services/shared/invocation_context.py +++ b/invokeai/app/services/shared/invocation_context.py @@ -1,3 +1,4 @@ +from copy import deepcopy from dataclasses import dataclass from pathlib import Path from typing import TYPE_CHECKING, Callable, Optional, Union @@ -294,15 +295,15 @@ def save(self, tensor: Tensor) -> str: return name def load(self, name: str) -> Tensor: - """Loads a tensor by name. + """Loads a tensor by name. This method returns a copy of the tensor. Args: name: The name of the tensor to load. Returns: - The loaded tensor. + The tensor. """ - return self._services.tensors.load(name) + return self._services.tensors.load(name).clone() class ConditioningInterface(InvocationContextInterface): @@ -320,16 +321,16 @@ def save(self, conditioning_data: ConditioningFieldData) -> str: return name def load(self, name: str) -> ConditioningFieldData: - """Loads conditioning data by name. + """Loads conditioning data by name. This method returns a copy of the conditioning data. Args: name: The name of the conditioning data to load. Returns: - The loaded conditioning data. + The conditioning data. """ - return self._services.conditioning.load(name) + return deepcopy(self._services.conditioning.load(name)) class ModelsInterface(InvocationContextInterface):