vendredi 24 juillet 2015

sqlite3 InterfaceError after upgrading to Peewee 2.6

After upgrading to Peewee 2.6.3 from v2.4.7, the following error pops up when iterating on results from a select query.

 File "./script.py", line 137, in load_data
    for name,country in rows:
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/peewee.py", line 1957, in next
    obj = self.iterate()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/peewee.py", line 1934, in iterate
    row = self.cursor.fetchone()
sqlite3.InterfaceError: Cursor needed to be reset because of commit/rollback and can no longer be fetched from. 

Here is the offending code:

for i in range(1, nb_rows // CHUNK_SIZE + 2):                                                                                                                                                                                                                                                                                                     
    rows = (Source.select(Source.name,Source.country)                                                                                                                       
           .where(Source.status == 'new').paginate(i, CHUNK_SIZE).tuples())                                                                                                     

    for name,country in rows:                                                                                                                                                                                                                                                                                                               
        person, created = Person.create_or_get(name = name, new = True)                                                                                                        

        if country:                                                                                                                                                                   
            country, created = Countries.create_or_get(name = country)                                                                                                                         
            Person_Country(person_id = person.id, country_id = country.id).save()   

Can you help me identify what the problem is and how to fix it?

Note: using Sqlite3 3.8.9

Aucun commentaire:

Enregistrer un commentaire