Skip to content

Commit 21a3b81

Browse files
authored
Random cleanup and bugfixes (#3709)
* Remove unused check * Ensure valid stack during creation * Ensure valid stack during update * Linting * Fix invalid stack request in tests * Formatting
1 parent 038b9c3 commit 21a3b81

File tree

3 files changed

+61
-30
lines changed

3 files changed

+61
-30
lines changed

src/zenml/client.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,9 +1480,6 @@ def active_stack_model(self) -> StackResponse:
14801480
14811481
Returns:
14821482
The model of the active stack for this client.
1483-
1484-
Raises:
1485-
RuntimeError: If the active stack is not set.
14861483
"""
14871484
if env_stack_id := os.environ.get(ENV_ZENML_ACTIVE_STACK_ID):
14881485
if not self._active_stack or self._active_stack.id != UUID(
@@ -1509,12 +1506,6 @@ def active_stack_model(self) -> StackResponse:
15091506

15101507
stack_id = GlobalConfiguration().get_active_stack_id()
15111508

1512-
if not stack_id:
1513-
raise RuntimeError(
1514-
"No active stack is configured. Run "
1515-
"`zenml stack set STACK_NAME` to set the active stack."
1516-
)
1517-
15181509
return self.get_stack(stack_id)
15191510

15201511
def activate_stack(
@@ -1550,9 +1541,6 @@ def _validate_stack_configuration(self, stack: StackRequest) -> None:
15501541
15511542
Args:
15521543
stack: The stack to validate.
1553-
1554-
Raises:
1555-
ValidationError: If the stack configuration is invalid.
15561544
"""
15571545
local_components: List[str] = []
15581546
remote_components: List[str] = []
@@ -1617,13 +1605,6 @@ def _validate_stack_configuration(self, stack: StackRequest) -> None:
16171605
f"local resources."
16181606
)
16191607

1620-
if not stack.is_valid:
1621-
raise ValidationError(
1622-
"Stack configuration is invalid. A valid"
1623-
"stack must contain an Artifact Store and "
1624-
"an Orchestrator."
1625-
)
1626-
16271608
# ----------------------------- Services -----------------------------------
16281609

16291610
def create_service(

src/zenml/models/v2/core/stack.py

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
)
2828
from uuid import UUID
2929

30-
from pydantic import Field, model_validator
30+
from pydantic import Field, field_validator, model_validator
3131
from sqlmodel import and_
3232

3333
from zenml.constants import STR_FIELD_MAX_LENGTH
@@ -94,18 +94,31 @@ class StackRequest(UserScopedRequest):
9494
"scratch.",
9595
)
9696

97-
@property
98-
def is_valid(self) -> bool:
99-
"""Check if the stack is valid.
97+
@field_validator("components")
98+
def _validate_components(
99+
cls, value: Dict[StackComponentType, List[Union[UUID, ComponentInfo]]]
100+
) -> Dict[StackComponentType, List[Union[UUID, ComponentInfo]]]:
101+
"""Validate the components of the stack.
102+
103+
Args:
104+
value: The components of the stack.
105+
106+
Raises:
107+
ValueError: If the stack does not contain an orchestrator and
108+
artifact store.
100109
101110
Returns:
102-
True if the stack is valid, False otherwise.
111+
The components of the stack.
103112
"""
104-
if not self.components:
105-
return False
106-
return (
107-
StackComponentType.ARTIFACT_STORE in self.components
108-
and StackComponentType.ORCHESTRATOR in self.components
113+
if value:
114+
artifact_stores = value.get(StackComponentType.ARTIFACT_STORE, [])
115+
orchestrators = value.get(StackComponentType.ORCHESTRATOR, [])
116+
117+
if orchestrators and artifact_stores:
118+
return value
119+
120+
raise ValueError(
121+
"Stack must contain at least an orchestrator and artifact store."
109122
)
110123

111124
@model_validator(mode="after")
@@ -163,6 +176,39 @@ class StackUpdate(BaseUpdate):
163176
title="The stack labels.",
164177
)
165178

179+
@field_validator("components")
180+
def _validate_components(
181+
cls,
182+
value: Optional[
183+
Dict[StackComponentType, List[Union[UUID, ComponentInfo]]]
184+
],
185+
) -> Optional[Dict[StackComponentType, List[Union[UUID, ComponentInfo]]]]:
186+
"""Validate the components of the stack.
187+
188+
Args:
189+
value: The components of the stack.
190+
191+
Raises:
192+
ValueError: If the stack does not contain an orchestrator and
193+
artifact store.
194+
195+
Returns:
196+
The components of the stack.
197+
"""
198+
if value is None:
199+
return None
200+
201+
if value:
202+
artifact_stores = value.get(StackComponentType.ARTIFACT_STORE, [])
203+
orchestrators = value.get(StackComponentType.ORCHESTRATOR, [])
204+
205+
if orchestrators and artifact_stores:
206+
return value
207+
208+
raise ValueError(
209+
"Stack must contain at least an orchestrator and artifact store."
210+
)
211+
166212

167213
# ------------------ Response Model ------------------
168214

tests/integration/functional/zen_stores/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,11 @@ def cleanup(self) -> None:
11671167
remote_stack_crud_test_config = CrudTestConfig(
11681168
create_model=StackRequest(
11691169
name=sample_name("remote_stack"),
1170-
components={},
1170+
# These will be replaced later by the conditional entities
1171+
components={
1172+
"orchestrator": [uuid.uuid4()],
1173+
"artifact_store": [uuid.uuid4()],
1174+
},
11711175
),
11721176
filter_model=StackFilter,
11731177
entity_name="stack",

0 commit comments

Comments
 (0)