fix(nodes): add RangeInvocation validator

`stop` must be greater than `start`.
This commit is contained in:
psychedelicious 2023-05-24 13:59:36 +10:00 committed by Kent Keirsey
parent 6f78c073ed
commit 55b3193629

View File

@ -3,7 +3,7 @@
from typing import Literal, Optional from typing import Literal, Optional
import numpy as np import numpy as np
from pydantic import Field from pydantic import Field, validator
from invokeai.app.util.misc import SEED_MAX, get_random_seed from invokeai.app.util.misc import SEED_MAX, get_random_seed
@ -33,6 +33,12 @@ class RangeInvocation(BaseInvocation):
stop: int = Field(default=10, description="The stop of the range") stop: int = Field(default=10, description="The stop of the range")
step: int = Field(default=1, description="The step of the range") step: int = Field(default=1, description="The step of the range")
@validator("stop")
def stop_gt_start(cls, v, values):
if "start" in values and v <= values["start"]:
raise ValueError("stop must be greater than start")
return v
def invoke(self, context: InvocationContext) -> IntCollectionOutput: def invoke(self, context: InvocationContext) -> IntCollectionOutput:
return IntCollectionOutput( return IntCollectionOutput(
collection=list(range(self.start, self.stop, self.step)) collection=list(range(self.start, self.stop, self.step))