Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions orchestrator/core/discoveryspace/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,22 @@ def perform_checks(
)

operation_id = kwargs.get("operation_id") or args[0]
space_for_operation = self._metadataStore.getResource(
identifier=operation_id,
kind=CoreResourceKinds.OPERATION,
raise_error_if_no_resource=True,
).config.spaces[0]

if self.uri != space_for_operation:
raise ValueError(
f"Operation {operation_id} does not belong to space {self.uri}, but rather to {space_for_operation}"
)
# Skip the DB round-trip when we've already verified this operation
# belongs to this space (e.g. the space was built via from_operation_id).
if operation_id not in self._verified_operation_ids:
space_for_operation = self._metadataStore.getResource(
identifier=operation_id,
kind=CoreResourceKinds.OPERATION,
raise_error_if_no_resource=True,
).config.spaces[0]

if self.uri != space_for_operation:
raise ValueError(
f"Operation {operation_id} does not belong to space {self.uri}, but rather to {space_for_operation}"
)

self._verified_operation_ids.add(operation_id)

return f(self, *args, **kwargs)

Expand Down Expand Up @@ -291,11 +297,13 @@ def from_operation_id(
raise_error_if_no_resource=True,
).config.spaces[0]

return cls.from_stored_configuration(
space = cls.from_stored_configuration(
project_context=project_context,
space_identifier=space_id,
metadata_store=metadata_store,
)
space._verified_operation_ids.add(operation_id)
return space

def __init__(
self,
Expand Down Expand Up @@ -385,6 +393,10 @@ def __init__(
else f"space-{str(uuid.uuid4())[:6]}-{self._sample_store.identifier}"
)

# Operation IDs that have already passed the preflight ownership check.
# Pre-populated by from_operation_id to avoid a redundant DB round-trip.
self._verified_operation_ids: set[str] = set()

def __rich__(self) -> "RenderableType":
"""Rich console representation of the DiscoverySpace."""
import rich.box
Expand Down