Skip to content

Commit c802c41

Browse files
committed
REF: Simplify EventAttributes.make_opposite_attributes
skipci
1 parent 398129d commit c802c41

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

octue/cloud/events/attributes.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
import datetime as dt
23
import uuid as uuid_library
34

@@ -89,17 +90,17 @@ def make_opposite_attributes(self):
8990
9091
:return octue.cloud.events.attributes.EventAttributes: the event attributes for an event with the opposite sender type
9192
"""
92-
attributes = self.to_minimal_dict()
93-
attributes["sender"] = self.recipient
94-
attributes["recipient"] = self.sender
95-
attributes["sender_type"] = SENDER_TYPE_OPPOSITES[self.sender_type]
96-
attributes["sender_sdk_version"] = LOCAL_SDK_VERSION
93+
attributes = copy.copy(self)
94+
attributes.sender = self.recipient
95+
attributes.recipient = self.sender
96+
attributes.sender_type = SENDER_TYPE_OPPOSITES[self.sender_type]
97+
attributes.sender_sdk_version = LOCAL_SDK_VERSION
9798

99+
# Response attributes don't have these attributes set.
98100
for attr in ("forward_logs", "save_diagnostics", "cpus", "memory", "ephemeral_storage"):
99-
if attr in attributes:
100-
del attributes[attr]
101+
setattr(self, attr, None)
101102

102-
return EventAttributes(**attributes)
103+
return attributes
103104

104105
def to_minimal_dict(self):
105106
"""Convert the attributes to a minimal dictionary containing only the attributes that have a non-`None` value.

0 commit comments

Comments
 (0)