Conjure python types are not picklable
JacekLach opened this issue · 0 comments
JacekLach commented
What happened?
#317 broke pickling of conjure types
>>> from ontology_metadata_api.ontology_metadata_api import RuleSetBinding
>>> binding = RuleSetBinding(bindings={}, rule_set_rid="some.rid")
>>>
>>> import pickle
>>> pickle.dumps(binding, pickle.HIGHEST_PROTOCOL)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.PicklingError: Can't pickle <class 'ontology_metadata_api.ontology_metadata_api.ontology_metadata_api_RuleSetBinding'>: attribute lookup ontology_metadata_api_RuleSetBinding on ontology_metadata_api.ontology_metadata_api failed
This is because:
>>> binding.__class__
<class 'ontology_metadata_api.ontology_metadata_api.ontology_metadata_api_RuleSetBinding'>
__class__
points to a reference that is not valid
Fix:
>>> binding.__class__.__name__
'RuleSetBinding'
>>> binding.__class__.__qualname__
'ontology_metadata_api_RuleSetBinding'
>>> binding.__class__.__qualname__ = binding.__class__.__name__
>>> binding.__class__
<class 'ontology_metadata_api.ontology_metadata_api.RuleSetBinding'>
>>> pickle.dumps(binding, pickle.HIGHEST_PROTOCOL)
b'\x80\x04\x95v\x00\x00\x00\x00\x00\x00\x00\x8c+ontology_metadata_api.ontology_metadata_api\x94\x8c\x0eRuleSetBinding\x94\x93\x94)\x81\x94N}\x94(\x8c\r_rule_set_rid\x94\x8c\x08some.rid\x94\x8c\t_bindings\x94}\x94u\x86\x94b.'