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

Tweet object fails to unpickle with built-in pickle #2059

Closed
achimgaedke opened this issue Feb 3, 2023 · 2 comments
Closed

Tweet object fails to unpickle with built-in pickle #2059

achimgaedke opened this issue Feb 3, 2023 · 2 comments
Labels
Duplicate This is a duplicate Question This is a question

Comments

@achimgaedke
Copy link

The code (python 3.11 and tweepy 4.12.1):

import tweepy
t = tweepy.Tweet(data={'edit_history_tweet_ids': ['16213149247090909'],
                       'id': '16213149247090909',
                       'text': "We're super excited to not only welcome the Flamingo Janes in..."})

import pickle
pickled_tweet = pickle.dumps(t)
pickle.loads(pickled_tweet)

fails with a recursion error and is related to bug #1792 .
(Why not using the data attribute to serialise the object? Initially I wasn't sure whether data contains actually the full state of the object... would be great to clarify in the docs.)

---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
Cell In[3], line 3
      1 import pickle
      2 pickled_tweet = pickle.dumps(t)
----> 3 pickle.loads(pickled_tweet)

File /usr/local/Caskroom/miniforge/base/envs/wellington-on-a-good-day/lib/python3.11/site-packages/tweepy/mixins.py:33, in DataMapping.__getattr__(self, name)
     31 def __getattr__(self, name):
     32     try:
---> 33         return self.data[name]
     34     except KeyError:
     35         raise AttributeError from None

File /usr/local/Caskroom/miniforge/base/envs/wellington-on-a-good-day/lib/python3.11/site-packages/tweepy/mixins.py:33, in DataMapping.__getattr__(self, name)
     31 def __getattr__(self, name):
     32     try:
---> 33         return self.data[name]
     34     except KeyError:
     35         raise AttributeError from None

    [... skipping similar frames: DataMapping.__getattr__ at line 33 (2970 times)]

File /usr/local/Caskroom/miniforge/base/envs/wellington-on-a-good-day/lib/python3.11/site-packages/tweepy/mixins.py:33, in DataMapping.__getattr__(self, name)
     31 def __getattr__(self, name):
     32     try:
---> 33         return self.data[name]
     34     except KeyError:
     35         raise AttributeError from None

RecursionError: maximum recursion depth exceeded

Reading https://docs.python.org/3/library/pickle.html#pickling-class-instances, I can re-create this by using

obj = tweepy.Tweet.__new__(tweepy.Tweet)
obj.__dict__.update(t.__dict__)
@achimgaedke
Copy link
Author

Fixed with #2060

@Harmon758
Copy link
Member

Duplicate of #1792

As discussed in that issue, the use case for this is unclear.

Tweet.data is documented.

@Harmon758 Harmon758 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 3, 2023
@Harmon758 Harmon758 added Question This is a question Duplicate This is a duplicate labels Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate This is a duplicate Question This is a question
Projects
None yet
Development

No branches or pull requests

2 participants