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

examples.export_retweet_text() is throwing a peewee error. Unsure how to debug. #17

Open
Vix18 opened this issue Jun 15, 2018 · 4 comments

Comments

@Vix18
Copy link

Vix18 commented Jun 15, 2018

I'm going through the tutorial but the export_retweet_text function is throwing an error in peewee. As I'm not familiar with SQL syntax or the peewee library I wondered if someone could give me a hint on debugging or resolving this issue?

here's my input. All the other functions so far have worked fine.

examples.export_retweet_text()

and here's the error message I get:

---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/peewee.py in get(self)
   3219         try:
-> 3220             return next(clone.execute())
   3221         except StopIteration:

playhouse/_speedups.pyx in playhouse._speedups._QueryResultWrapper.__next__()

playhouse/_speedups.pyx in playhouse._speedups._QueryResultWrapper.iterate()

StopIteration: 

During handling of the above exception, another exception occurred:

TweetDoesNotExist                         Traceback (most recent call last)
<ipython-input-31-1934918c595d> in <module>()
----> 1 examples.export_retweet_text()
      2 #retweet_text = pd.read_csv("retweet_text.csv")

~/Desktop/DS/Twitter/twitterresearch/examples.py in export_retweet_text(n)
    496         database.Tweet.retweet.is_null(False)).group_by(database.Tweet.retweet)
    497     for tweet in retweets:
--> 498         rt_counts[tweet.retweet.id] = tweet.retweet.retweets.count()
    499     from collections import Counter
    500     c = Counter(rt_counts)

~/anaconda3/lib/python3.6/site-packages/peewee.py in __get__(self, instance, instance_type)
   1384     def __get__(self, instance, instance_type=None):
   1385         if instance is not None:
-> 1386             return self.get_object_or_id(instance)
   1387         return self.field
   1388 

~/anaconda3/lib/python3.6/site-packages/peewee.py in get_object_or_id(self, instance)
   1375         if rel_id is not None or self.att_name in instance._obj_cache:
   1376             if self.att_name not in instance._obj_cache:
-> 1377                 obj = self.rel_model.get(self.field.to_field == rel_id)
   1378                 instance._obj_cache[self.att_name] = obj
   1379             return instance._obj_cache[self.att_name]

~/anaconda3/lib/python3.6/site-packages/peewee.py in get(cls, *query, **kwargs)
   4986         if kwargs:
   4987             sq = sq.filter(**kwargs)
-> 4988         return sq.get()
   4989 
   4990     @classmethod

~/anaconda3/lib/python3.6/site-packages/peewee.py in get(self)
   3222             raise self.model_class.DoesNotExist(
   3223                 'Instance matching query does not exist:\nSQL: %s\nPARAMS: %s'
-> 3224                 % self.sql())
   3225 
   3226     def peek(self, n=1):

TweetDoesNotExist: Instance matching query does not exist:
SQL: SELECT "t1"."id", "t1"."user_id", "t1"."text", "t1"."date", "t1"."language_id", "t1"."reply_to_user_id", "t1"."reply_to_tweet", "t1"."retweet_id" FROM "tweet" AS t1 WHERE ("t1"."id" = ?)
PARAMS: [0]
@trifle
Copy link
Owner

trifle commented Jun 18, 2018

Hi @Vix18, it seems your database is either empty or you are attempting to get a non-existing tweet.
The interesting part are the last few lines of the output:

TweetDoesNotExist (that's the exception's name).
The database looked for a tweet with ID=0 (that's the PARAMS at the end).

You could verify whether there are any tweets stored in the DB by opening an interactive python shell, importing the DB script and querying manually, i.e. along these lines:

import database

total_tweet_count = database.Tweet.select().count()
print(total_tweet_count)

etc.

@Vix18
Copy link
Author

Vix18 commented Jun 19, 2018

Thanks - that makes sense; the database is there but I wasn't able to hydrate all of them; this function must be looking for one of the missing tweets.

@trifle
Copy link
Owner

trifle commented Jun 20, 2018

Did you find/fix the error? If there is a problem replicating the basic examples from the tutorial using our dehydrated data, I'd love to know and fix that.

@Vix18
Copy link
Author

Vix18 commented Jun 20, 2018 via email

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

No branches or pull requests

2 participants