You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When unpickling a pickled FakeFilesystem object, the getattr method of FakeFile loops forever.
import pickle
from pyfakefs import fake_filesystem
filesystem = fake_filesystem.FakeFilesystem()
filesystem.open_files = []
p = pickle.dumps(filesystem)
pickle.loads(p)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File ".local/lib/python3.6/site-packages/pyfakefs/fake_filesystem.py", line 477, in __getattr__
return getattr(self.stat_result, item)
File ".local/lib/python3.6/site-packages/pyfakefs/fake_filesystem.py", line 477, in __getattr__
return getattr(self.stat_result, item)
File ".local/lib/python3.6/site-packages/pyfakefs/fake_filesystem.py", line 477, in __getattr__
return getattr(self.stat_result, item)
[Previous line repeated 323 more times]
RecursionError: maximum recursion depth exceeded
The fix is fairly simple, use the same conditional as setattr already does :
--- fake_filesystem.py.orig 2018-10-24 14:05:28.497666345 +0300
+++ fake_filesystem.py 2018-10-15 14:32:20.872485946 +0300
@@ -471,13 +471,15 @@
st_ctime: The desired creation time.
"""
self.st_ctime = st_ctime
def __getattr__(self, item):
"""Forward some properties to stat_result."""
- return getattr(self.stat_result, item)
+ if item in self.stat_types:
+ return getattr(self.stat_result, item)
+ return super(FakeFile, self).__getattr__(item)
def __setattr__(self, key, value):
"""Forward some properties to stat_result."""
if key in self.stat_types:
return setattr(self.stat_result, key, value)
return super(FakeFile, self).__setattr__(key, value)
I can make a pull request if needed
The text was updated successfully, but these errors were encountered:
Thanks - could have sworn I already fixed that some time ago... ah well.
I can fix this in the evening, or you can make a PR - as you said, the fix is trivial.
Hm, this works nice in Python 3, but not in Python 2.
Pickling doesn't work there because FakeStatResult uses a class method as a member variable , which cannot be pickled out of the box in Python 2. This can be solved, but the other problem is that the current implementation replaces that with a lambda function on copy to simulate the real behavior. This can also not be pickled in Python 2, and seems to be a little more complicated to handle.
I will think a bit more about this - maybe have another go tomorrow...
When unpickling a pickled FakeFilesystem object, the getattr method of FakeFile loops forever.
The fix is fairly simple, use the same conditional as setattr already does :
I can make a pull request if needed
The text was updated successfully, but these errors were encountered: