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
datetime.timedelta not picklable if unpicklable == False #444
Comments
That's very interesting, I have no clue what's happening here. I'll try and investigate it soon. Is this crucial for your use-case, or can it wait a bit? I have a few other projects I'm working on plus I'm moving on Sunday, so I'm a bit busy currently. |
It can definitely wait. I really appreciate your asking! Good luck with the move -- that's always a big project!! |
It seems like it was an intentional choice by the maintainers before me to have circular objects become None when pickled with if self.unpicklable:
...
else:
max_reached = self._max_reached()
in_cycle = _in_cycle(obj, self._objs, max_reached, False)
if in_cycle:
# A circular becomes None.
return None Found here |
I don't think from datetime import timedelta
import jsonpickle
def main():
td = timedelta(seconds=1)
print(f'{td=}')
td_json_str = jsonpickle.encode(td, unpicklable=False)
print(f'{td_json_str=}')
if __name__ == '__main__':
main() and the File: pickler.py
658: # catchall return for data created above without a return
659: # (e.g. __getnewargs__ is not supposed to be the end of the story)
660: if data:
661: return data
662:
663: self._pickle_warning(obj)
664: return None I'm wondering if perhaps the issue (no |
I don't understand why only the Once there's a release with the fix for #443, I intend to use |
Unfortunately there is no official design document/history to know why these choices were made. I only started working on jsonpickle in late 2020, and jsonpickle started in 2009, so I don't really know the reasoning behind much of the code-base. Maybe @davvid can provide some insights? My best guess is that since |
I guess my main point is that there are builtin types, like Python 3.11.3 (tags/v3.11.3:f3909b8, Apr 4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import timedelta
>>> td = timedelta(seconds=3)
>>> td
datetime.timedelta(seconds=3)
>>> td.__getstate__()
>>> td.__reduce__()
(<class 'datetime.timedelta'>, (0, 3, 0)) It seems to me that |
Maybe related #447 |
But, for example, other "lossy" one-way encodings are supported with unpicklable
True
orFalse
:The text was updated successfully, but these errors were encountered: