Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit 4d1fedb

Browse files
robertwbaaltay
authored andcommitted
Fix module dict pickling.
----Release Notes---- [] ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=124179749
1 parent ecaea38 commit 4d1fedb

2 files changed

Lines changed: 70 additions & 57 deletions

File tree

google/cloud/dataflow/internal/pickler.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,20 @@ def new_save_module_dict(pickler, obj):
138138
for m in sys.modules.values():
139139
try:
140140
if m and m.__name__ != '__main__':
141-
known_module_dicts[id(m.__dict__)] = m
141+
d = m.__dict__
142+
known_module_dicts[id(d)] = m, d
142143
except AttributeError:
143144
# Skip modules that do not have the __name__ attribute.
144145
pass
145-
# TODO(silviuc): Must investigate the disabled if branch below.
146-
if obj_id in known_module_dicts and dill.dill.is_dill(pickler) and False:
147-
return pickler.save_reduce(
148-
getattr, (known_module_dicts[obj_id], '__dict__'), obj=obj)
146+
if obj_id in known_module_dicts and dill.dill.is_dill(pickler):
147+
m = known_module_dicts[obj_id][0]
148+
try:
149+
# pylint: disable=protected-access
150+
dill.dill._import_module(m.__name__)
151+
return pickler.save_reduce(
152+
getattr, (known_module_dicts[obj_id][0], '__dict__'), obj=obj)
153+
except (ImportError, AttributeError):
154+
return old_save_module_dict(pickler, obj)
149155
else:
150156
return old_save_module_dict(pickler, obj)
151157
dill.dill.save_module_dict = new_save_module_dict

0 commit comments

Comments
 (0)