These tests fail, so beware that even deepcopy is not doing what you think. Workaround is pickle.loads(pickle.dumps(aca)). I'm surprised that deepcopy() doesn't work since I thought that actually used the pickle __setstate__ and __getstate__ methods.
aca = get_aca_catalog(**KWARGS_48464)
aca2 = aca.__class__(aca) # default is copy=True
assert aca2.acqs is not aca.acqs
for probs in aca2.acqs.cand_acqs['probs']:
assert probs.acqs() is aca2.acqs
aca3 = deepcopy(aca)
for probs in aca3.acqs.cand_acqs['probs']:
assert probs.acqs() is aca3.acqs
I'd like to fix this but initial attempts fell short. The issue revolves around the weakref in the AcqProb objects in the cand_acqs table. This is all a bit fragile and should be reworked, but not for 4.4 since it would be a big change.
However, this does work:
acar = ACAReviewTable(aca)
assert aca.guides is not acar.guides
assert aca.acqs is not acar.acqs
del aca
gc.collect()
# Make sure object is self-consistent and self-contained.
for probs in acar.acqs.cand_acqs['probs']:
assert probs.acqs() is acar.acqs
These tests fail, so beware that even deepcopy is not doing what you think. Workaround is
pickle.loads(pickle.dumps(aca))
. I'm surprised that deepcopy() doesn't work since I thought that actually used the pickle__setstate__
and__getstate__
methods.I'd like to fix this but initial attempts fell short. The issue revolves around the weakref in the AcqProb objects in the
cand_acqs
table. This is all a bit fragile and should be reworked, but not for 4.4 since it would be a big change.However, this does work: