Skip to content
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

gergo/applicationIdAttach #391

Open
wants to merge 1 commit into
base: v3-dev
Choose a base branch
from
Open
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
29 changes: 16 additions & 13 deletions src/speckle_automate/automation_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def _mark_run(
def attach_error_to_objects(
self,
category: str,
object_ids: Union[str, List[str]],
objects: Union[Base, List[Base]],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are changing this anyway, I think requiring a List[Base] only is preferable to either a single or a list

message: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
visual_overrides: Optional[Dict[str, Any]] = None,
Expand All @@ -351,7 +351,7 @@ def attach_error_to_objects(
self.attach_result_to_objects(
ObjectResultLevel.ERROR,
category,
object_ids,
objects,
message,
metadata,
visual_overrides,
Expand All @@ -360,7 +360,7 @@ def attach_error_to_objects(
def attach_warning_to_objects(
self,
category: str,
object_ids: Union[str, List[str]],
objects: Union[Base, List[Base]],
message: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
visual_overrides: Optional[Dict[str, Any]] = None,
Expand All @@ -369,7 +369,7 @@ def attach_warning_to_objects(
self.attach_result_to_objects(
ObjectResultLevel.WARNING,
category,
object_ids,
objects,
message,
metadata,
visual_overrides,
Expand All @@ -378,7 +378,7 @@ def attach_warning_to_objects(
def attach_success_to_objects(
self,
category: str,
object_ids: Union[str, List[str]],
objects: Union[Base, List[Base]],
message: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
visual_overrides: Optional[Dict[str, Any]] = None,
Expand All @@ -387,7 +387,7 @@ def attach_success_to_objects(
self.attach_result_to_objects(
ObjectResultLevel.SUCCESS,
category,
object_ids,
objects,
message,
metadata,
visual_overrides,
Expand All @@ -396,7 +396,7 @@ def attach_success_to_objects(
def attach_info_to_objects(
self,
category: str,
object_ids: Union[str, List[str]],
objects: Union[Base, List[Base]],
message: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
visual_overrides: Optional[Dict[str, Any]] = None,
Expand All @@ -405,7 +405,7 @@ def attach_info_to_objects(
self.attach_result_to_objects(
ObjectResultLevel.INFO,
category,
object_ids,
objects,
message,
metadata,
visual_overrides,
Expand All @@ -415,19 +415,22 @@ def attach_result_to_objects(
self,
level: ObjectResultLevel,
category: str,
object_ids: Union[str, List[str]],
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:
if isinstance(objects, list):
if len(objects) < 1:
raise ValueError(
f"Need atleast one object_id to report a(n) {level.value.upper()}"
)
id_list = object_ids
id_list = [o.id for o in objects]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not a fan of this - partly because we are storing a list of objects as result data contextual to the objects - ids worked well here as there wasn't an inference the developer could make that this could be NEW Base objects.

We don't serialize these objects in the same way as a Send, do we???

application_ids = [o.applicationId for o in objects]
else:
id_list = [object_ids]
id_list = [objects.id]
application_ids = [objects.applicationId]
metadata["applicationIds"] = application_ids
print(
f"Created new {level.value.upper()}"
f" category: {category} caused by: {message}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def automate_function(
raise ValueError("Cannot operate on objects without their id's.")
automation_context.attach_error_to_objects(
"Forbidden speckle_type",
version_root_object.id,
version_root_object,
"This project should not contain the type: "
f"{function_inputs.forbidden_speckle_type}",
)
Expand Down