Skip to content

Commit 6688cbd

Browse files
yt-msMidnighter
authored andcommitted
fix: restore correct inheritance hierarchy for StaticStructureElementIO
1 parent dbd21f8 commit 6688cbd

File tree

2 files changed

+10
-31
lines changed

2 files changed

+10
-31
lines changed

src/structurizr/model/static_structure_element_instance.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,21 @@
1919
from abc import ABC
2020
from typing import Iterable, List, Optional
2121

22-
from pydantic import Field, HttpUrl
22+
from pydantic import Field
2323

24-
from .deployment_element import DEFAULT_DEPLOYMENT_ENVIRONMENT, DeploymentElement
24+
from .deployment_element import DeploymentElement, DeploymentElementIO
2525
from .http_health_check import HTTPHealthCheck, HTTPHealthCheckIO
26-
from .model_item import ModelItem, ModelItemIO
27-
from .relationship import Relationship, RelationshipIO
2826
from .static_structure_element import StaticStructureElement
2927

3028

3129
__all__ = ("StaticStructureElementInstance", "StaticStructureElementInstanceIO")
3230

3331

34-
class StaticStructureElementInstanceIO(ModelItemIO, ABC):
35-
"""
36-
Define a superclass for instances of container and software system.
32+
class StaticStructureElementInstanceIO(DeploymentElementIO, ABC):
33+
"""Define a superclass for instances of container and software system."""
3734

38-
Implementation note:
39-
In this case, the IO does not reflect the same inheritance hierarchy
40-
as the main class. This is because instances do not have the `name` field
41-
and so we cannot extend `ElementIO` which enforces that `name` is populated.
42-
See http://github.com/structurizr/json/blob/master/structurizr.yaml.
43-
"""
35+
name: Optional[str] = "" # Name is not serialisable for instances
4436

45-
description: str = Field(default="")
46-
url: Optional[HttpUrl] = Field(default=None)
47-
relationships: List[RelationshipIO] = Field(default=())
48-
49-
environment: Optional[str] = DEFAULT_DEPLOYMENT_ENVIRONMENT
5037
instance_id: int = Field(alias="instanceId")
5138
health_checks: List[HTTPHealthCheckIO] = Field(default=(), alias="healthChecks")
5239

@@ -65,21 +52,17 @@ def __init__(
6552
"""Initialize a StaticStructureElementInstance."""
6653
# The name of the instance comes from element it contains - see
6754
# StaticStructureElementInstance.getName() in the Java API.
68-
super().__init__(name=element.name, **kwargs)
55+
kwargs["name"] = element.name
56+
super().__init__(**kwargs)
6957
self.instance_id = instance_id
7058
self.health_checks = set(health_checks)
7159

7260
@classmethod
7361
def hydrate_arguments(cls, instance_io: StaticStructureElementInstanceIO) -> dict:
7462
"""Build constructor arguments from IO."""
7563

76-
# See note in DeploymentInstanceIO on why we're not using super() here.
7764
return {
78-
**ModelItem.hydrate_arguments(instance_io),
79-
"description": instance_io.description,
80-
"url": instance_io.url,
81-
"relationships": map(Relationship.hydrate, instance_io.relationships),
82-
"environment": instance_io.environment,
65+
**super().hydrate_arguments(instance_io),
8366
"instance_id": instance_io.instance_id,
8467
"health_checks": map(HTTPHealthCheck.hydrate, instance_io.health_checks),
8568
}

tests/unit/model/test_container_instance.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ def test_container_instance_init(attributes):
7575

7676
def test_container_instance_hydration_retrieves_container_from_id(model_with_container):
7777
"""Check that the container instance is retrieved from the model on hydration."""
78-
io = ContainerInstanceIO(
79-
container_id="19", instance_id=3, environment="Live"
80-
)
78+
io = ContainerInstanceIO(container_id="19", instance_id=3, environment="Live")
8179

8280
instance = ContainerInstance.hydrate(io, model_with_container)
8381

@@ -89,9 +87,7 @@ def test_container_instance_hydration_retrieves_container_from_id(model_with_con
8987

9088
def test_container_instance_name_is_container_name(model_with_container):
9189
"""Ensure container instance takes its name from its container."""
92-
io = ContainerInstanceIO(
93-
container_id="19", instance_id=3, environment="Live"
94-
)
90+
io = ContainerInstanceIO(container_id="19", instance_id=3, environment="Live")
9591

9692
instance = ContainerInstance.hydrate(io, model_with_container)
9793

0 commit comments

Comments
 (0)