Skip to content

Commit 6a65b5e

Browse files
author
Jakub Urban
committed
Add custom serializer and de-serializer for pickle module
1 parent 263e9c3 commit 6a65b5e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/openshift/apiobject.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,3 +885,25 @@ def execute(self, cmd_to_exec=None, stdin=None, container_name=None, auto_raise=
885885
r.fail_if(
886886
"Error running {} exec on {} [rc={}]: {}".format(self.qname(), cmd_to_exec[0], r.status(), r.err()))
887887
return r
888+
889+
def __getstate__(self):
890+
"""
891+
Custom serializer for pickle module.
892+
The pickle module implements binary protocols for serializing and de-serializing a Python object structure.
893+
More info here: https://docs.python.org/3/library/pickle.html#object.__getstate__
894+
"""
895+
return {
896+
"name": self.model.metadata.name,
897+
"kind": self.model.kind,
898+
"context": self.context,
899+
}
900+
901+
def __setstate__(self, state):
902+
"""
903+
Custom de-serializing for pickle module.
904+
The pickle module implements binary protocols for serializing and de-serializing a Python object structure.
905+
More info here: https://docs.python.org/3/library/pickle.html#object.__setstate__
906+
"""
907+
with state["context"]:
908+
result = selector(f"{state['kind']}/{state['name']}").object_json()
909+
super().__init__(string_to_model=result)

0 commit comments

Comments
 (0)