-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PackedObjectReader
does not implement readline
- fails unpicking!
#174
Comments
The crux is that the bug will only appear when the pickled object is part of a pack. If it is a loose file, the API will return a normal file handle when opening it. However, if it is part of a pack, the The following script provides a minimal working example: #!/usr/bin/env python
import disk_objectstore
import pickle
import tempfile
with tempfile.TemporaryDirectory() as dirpath:
# Initialize a disk objectstore container
container = disk_objectstore.Container(dirpath)
container.init_container()
# Pickle an arbitrary object (a random string in this example) and write directly to a pack file
pickled_container = pickle.dumps('some-string')
if True:
key = container.add_objects_to_pack([pickled_container])[0]
else:
key = container.add_object(pickled_container)
# Retrieve the pickled byte stream and try to unpickle it
with container.get_object_stream(key) as handle:
pickle.load(handle) If the conditional is
If we switch it to So I think we just need to implement |
Thanks @sphuber. I'll open a PR draft soon and give it a go. |
In a use case where an output of a calculation (a
GeneralData
type of anaiida-workgraph
task) is automatically pickled and used as an input by a subsequent calculation,pickle
fails to unpickle the pickled output due to a missingreadline
method on the file handler, which is of typedisk-objectstore.utils.PackedObjectReader
.After chatting with @sphuber, it is understood that due to an optimization step by the
disk-objectstore
, the file handler changed fromio.BufferedReader
todisk_objectstore.utils.PackedObjectReader
. Unfortunately, as I'm unclear as to when this optimization takes place, I am unable to reproduce the issue at the moment, .In any case, though
disk_objectstore.utils.PackedObjectReader
implementsread
, it does not implementreadline
, both required bypickle
for unpickling. As such,pickle
fails to unpickle the output.@sphuber recommends/suggests that
disk_objectstore.utils.PackedObjectReader
is revisited to ensure it can be treated on an equal footing as anio.BufferedReader
.The text was updated successfully, but these errors were encountered: