Skip to content

feat(automate): attach application id-s to automate result cases #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
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
119 changes: 84 additions & 35 deletions src/speckle_automate/automation_context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# ignoring "line too long" check from linter
# ruff: noqa: E501
"""This module provides an abstraction layer above the Speckle Automate runtime."""

import time
Expand Down Expand Up @@ -75,7 +73,7 @@
speckle_client.authenticate_with_token(speckle_token)
if not speckle_client.account:
msg = (
f"Could not autenticate to {automation_run_data.speckle_server_url}",
f"Could not authenticate to {automation_run_data.speckle_server_url}",
"with the provided token",
)
raise ValueError(msg)
Expand Down Expand Up @@ -109,18 +107,24 @@
)
except SpeckleException as err:
raise ValueError(
f"""\
Could not receive specified version.
Is your environment configured correctly?
project_id: {self.automation_run_data.project_id}
model_id: {self.automation_run_data.triggers[0].payload.model_id}
version_id: {self.automation_run_data.triggers[0].payload.version_id}
"""
f"""Could not receive specified version.
Is your environment configured correctly?
project_id: {self.automation_run_data.project_id}
model_id: {self.automation_run_data.triggers[0].payload.model_id}
version_id: {self.automation_run_data.triggers[0].payload.version_id}
"""
) from err

if not version.referenced_object:
raise Exception(

Check warning on line 119 in src/speckle_automate/automation_context.py

View check run for this annotation

Codecov / codecov/patch

src/speckle_automate/automation_context.py#L118-L119

Added lines #L118 - L119 were not covered by tests
"This version is past the version history limit,",
" cannot execute an automation on it",
)

base = operations.receive(
version.referenced_object, self._server_transport, self._memory_transport
)
# self._closure_tree = base["__closure"]
print(
f"It took {self.elapsed():.2f} seconds to receive",
f" the speckle version {version_id}",
Expand Down Expand Up @@ -242,7 +246,7 @@
)
if self.run_status in [AutomationStatus.SUCCEEDED, AutomationStatus.FAILED]:
object_results = {
"version": 1,
"version": 2,
"values": {
"objectResults": self._automation_result.model_dump(by_alias=True)[
"objectResults"
Expand Down Expand Up @@ -332,26 +336,24 @@
def attach_error_to_objects(
self,
category: str,
object_ids: Union[str, List[str]],
affected_objects: Union[Base, List[Base]],
message: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
visual_overrides: Optional[Dict[str, Any]] = None,
) -> None:
"""Add a new error case to the run results.

If the error cause has already created an error case,
the error will be extended with a new case refering to the causing objects.
Args:
error_tag (str): A short tag for the error type.
causing_object_ids (str[]): A list of object_id-s that are causing the error
error_messagge (Optional[str]): Optional error message.
category (str): A short tag for the event type.
affected_objects (Union[Base, List[Base]]): A single object or a list of
objects that are causing the error case.
message (Optional[str]): Optional message.
metadata: User provided metadata key value pairs
visual_overrides: Case specific 3D visual overrides.
"""
self.attach_result_to_objects(
ObjectResultLevel.ERROR,
category,
object_ids,
affected_objects,
message,
metadata,
visual_overrides,
Expand All @@ -360,16 +362,25 @@
def attach_warning_to_objects(
self,
category: str,
object_ids: Union[str, List[str]],
affected_objects: Union[Base, List[Base]],
message: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
visual_overrides: Optional[Dict[str, Any]] = None,
) -> None:
"""Add a new warning case to the run results."""
"""Add a new warning case to the run results.

Args:
category (str): A short tag for the event type.
affected_objects (Union[Base, List[Base]]): A single object or a list of
objects that are causing the warning case.
message (Optional[str]): Optional message.
metadata: User provided metadata key value pairs
visual_overrides: Case specific 3D visual overrides.
"""
self.attach_result_to_objects(
ObjectResultLevel.WARNING,
category,
object_ids,
affected_objects,
message,
metadata,
visual_overrides,
Expand All @@ -378,16 +389,25 @@
def attach_success_to_objects(
self,
category: str,
object_ids: Union[str, List[str]],
affected_objects: Union[Base, List[Base]],
message: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
visual_overrides: Optional[Dict[str, Any]] = None,
) -> None:
"""Add a new success case to the run results."""
"""Add a new success case to the run results.

Args:
category (str): A short tag for the event type.
affected_objects (Union[Base, List[Base]]): A single object or a list of
objects that are causing the success case.
message (Optional[str]): Optional message.
metadata: User provided metadata key value pairs
visual_overrides: Case specific 3D visual overrides.
"""
self.attach_result_to_objects(
ObjectResultLevel.SUCCESS,
category,
object_ids,
affected_objects,
message,
metadata,
visual_overrides,
Expand All @@ -396,16 +416,25 @@
def attach_info_to_objects(
self,
category: str,
object_ids: Union[str, List[str]],
affected_objects: Union[Base, List[Base]],
message: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
visual_overrides: Optional[Dict[str, Any]] = None,
) -> None:
"""Add a new info case to the run results."""
"""Add a new info case to the run results.

Args:
category (str): A short tag for the event type.
affected_objects (Union[Base, List[Base]]): A single object or a list of
objects that are causing the info case.
message (Optional[str]): Optional message.
metadata: User provided metadata key value pairs
visual_overrides: Case specific 3D visual overrides.
"""
self.attach_result_to_objects(
ObjectResultLevel.INFO,
category,
object_ids,
affected_objects,
message,
metadata,
visual_overrides,
Expand All @@ -415,19 +444,39 @@
self,
level: ObjectResultLevel,
category: str,
object_ids: Union[str, List[str]],
affected_objects: Union[Base, List[Base]],
message: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
visual_overrides: Optional[Dict[str, Any]] = None,
) -> None:
if isinstance(object_ids, list):
if len(object_ids) < 1:
"""Add a new result case to the run results.

Args:
level: Result level.
category (str): A short tag for the event type.
affected_objects (Union[Base, List[Base]]): A single object or a list of
objects that are causing the info case.
message (Optional[str]): Optional message.
metadata: User provided metadata key value pairs
visual_overrides: Case specific 3D visual overrides.
"""
if isinstance(affected_objects, list):
if len(affected_objects) < 1:

Check warning on line 464 in src/speckle_automate/automation_context.py

View check run for this annotation

Codecov / codecov/patch

src/speckle_automate/automation_context.py#L463-L464

Added lines #L463 - L464 were not covered by tests
raise ValueError(
f"Need atleast one object_id to report a(n) {level.value.upper()}"
f"Need atleast one object to report a(n) {level.value.upper()}"
)
id_list = object_ids
object_list = affected_objects

Check warning on line 468 in src/speckle_automate/automation_context.py

View check run for this annotation

Codecov / codecov/patch

src/speckle_automate/automation_context.py#L468

Added line #L468 was not covered by tests
else:
id_list = [object_ids]
object_list = [affected_objects]

Check warning on line 470 in src/speckle_automate/automation_context.py

View check run for this annotation

Codecov / codecov/patch

src/speckle_automate/automation_context.py#L470

Added line #L470 was not covered by tests

ids: Dict[str, Optional[str]] = {}
for o in object_list:

Check warning on line 473 in src/speckle_automate/automation_context.py

View check run for this annotation

Codecov / codecov/patch

src/speckle_automate/automation_context.py#L472-L473

Added lines #L472 - L473 were not covered by tests
# validate that the Base.id is not None. If its a None, throw an Exception
if not o.id:
raise Exception(

Check warning on line 476 in src/speckle_automate/automation_context.py

View check run for this annotation

Codecov / codecov/patch

src/speckle_automate/automation_context.py#L475-L476

Added lines #L475 - L476 were not covered by tests
f"You can only attach {level} results to objects with an id."
)
ids[o.id] = o.applicationId

Check warning on line 479 in src/speckle_automate/automation_context.py

View check run for this annotation

Codecov / codecov/patch

src/speckle_automate/automation_context.py#L479

Added line #L479 was not covered by tests
print(
f"Created new {level.value.upper()}"
f" category: {category} caused by: {message}"
Expand All @@ -436,7 +485,7 @@
ResultCase(
category=category,
level=level,
object_ids=id_list,
object_app_ids=ids,
message=message,
metadata=metadata,
visual_overrides=visual_overrides,
Expand Down
2 changes: 1 addition & 1 deletion src/speckle_automate/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ResultCase(AutomateBase):

category: str
level: ObjectResultLevel
object_ids: List[str]
object_app_ids: Dict[str, Optional[str]]
message: Optional[str]
metadata: Optional[Dict[str, Any]]
visual_overrides: Optional[Dict[str, Any]]
Expand Down