Skip to content
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

Unpickling AiiDA Data nodes raises RecursionError #5285

Closed
jbweston opened this issue Dec 17, 2021 · 2 comments · Fixed by #5549
Closed

Unpickling AiiDA Data nodes raises RecursionError #5285

jbweston opened this issue Dec 17, 2021 · 2 comments · Fixed by #5549

Comments

@jbweston
Copy link

Describe the bug

Unpickling AiiDA types that were previously pickled raises RecursionError.

Steps to reproduce

import pickle

import aiida
from aiida.orm import Int, List

aiida.load_profile()
print(aiida.__version__)

s = pickle.dumps(Int(5))
pickle.loads(s)

produces the following stack trace:

---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
/tmp/ipykernel_14051/80999944.py in <module>
      8 
      9 s = pickle.dumps(Int(5))
---> 10 pickle.loads(s)

~/miniconda3/envs/aiida-latest/lib/python3.9/site-packages/aiida/orm/implementation/django/utils.py in __getattr__(self, item)
     52         :return: the value of the model's attribute
     53         """
---> 54         if self.is_saved() and self._is_mutable_model_field(item):
     55             self._ensure_model_uptodate(fields=(item,))
     56 

~/miniconda3/envs/aiida-latest/lib/python3.9/site-packages/aiida/orm/implementation/django/utils.py in is_saved(self)
     75         :return: boolean, True if the model is saved in the database, False otherwise
     76         """
---> 77         return self._model.pk is not None
     78 
     79     def save(self):

... last 2 frames repeated, from the frame below ...

~/miniconda3/envs/aiida-latest/lib/python3.9/site-packages/aiida/orm/implementation/django/utils.py in __getattr__(self, item)
     52         :return: the value of the model's attribute
     53         """
---> 54         if self.is_saved() and self._is_mutable_model_field(item):
     55             self._ensure_model_uptodate(fields=(item,))
     56 

RecursionError: maximum recursion depth exceeded

Same error is produced if the AiiDA node is first store()ed.

Expected behavior

If the node is not going to be unpickled cleanly I would expect an error to be raised when pickling (e.g. "don't pickle AiiDA nodes; you're probably doing something wrong").

Your environment

  • Operating system: Linux
  • Python version: 3.9
  • aiida-core version: Development (7fad822)

Other relevant software versions, e.g. Postres & RabbitMQ N/A

@sphuber
Copy link
Contributor

sphuber commented Dec 19, 2021

Thanks for the report @jbweston . Just for reference that this seems to be a problem with the Django backend, because for SqlAlchemy the code works fine:

In [1]: import pickle
   ...: node = Int(5)
   ...: s = pickle.dumps(node)
   ...: pickle.loads(s)
Out[1]: <Int: uuid: 4135440c-db75-4c00-b5ce-547c13642168 (unstored) value: 5>

Note that we are in the process of removing Django support and migrating automatically to SqlAlchemy and plan on releasing this with v2.0 in the upcoming months. If we don't find the time to find a fix for Django and backport it onto v1.6.5 that is.

@chrisjsewell
Copy link
Member

#5330 indeed removes django, I'm not sure on the use case for picking an aiida node though, and therefore if we can/should support it.

An aiida node is tied to a "backend" instance, e.g. the PSQL database / disk-objectstore repository that its data is referencing. If you pickle/unpickle a node, what are you expecting to get back: should it also pickle the backend instance, but then if the backend is unpickled I guess it is going to try to load a connection to the database, which does not seem good.

Suffice to say, I think we should probably just "disallow" pickling of nodes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants