JasonMillward / Autorippr

Rip discs automatically using a blend of Python, MakeMKV and HandBrake
MIT License
241 stars 60 forks source link

Peewee OperationalError when determining next_movie_to_compress #65

Closed IanDBird closed 9 years ago

IanDBird commented 9 years ago

Python 2.7 (r27:82500, Aug 21 2010, 07:52:47) [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

peewee (2.4.3)

When attempting to run Autorippr on my QNAP NAS, I get the following error:

>>> database.next_movie_to_compress()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "classes/database.py", line 116, in next_movie_to_compress
    for movie in Movies.select().where((Movies.statusid == 4) & (Movies.filename != None)):
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2483, in __iter__
    return iter(self.execute())
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2476, in execute
    self._qr = ResultWrapper(model_class, self._execute(), query_meta)
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2172, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2788, in execute_sql
    self.commit()
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2657, in __exit__
    reraise(new_type, new_type(*exc_value.args), traceback)
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2780, in execute_sql
    cursor.execute(sql, params or ())
peewee.OperationalError: near "?": syntax error

After debugging a bit, it turns out the (peewee) error occurs when performing building the SQL for the the Movies.filename != None and appears to due to the comparison with None, e.g.

>>> database.Movies.select().where((database.Movies.statusid == 4))
<class 'classes.database.Movies'> SELECT "t1"."movieID", "t1"."moviename", "t1"."path", "t1"."filename", "t1"."filebot", "t1"."statusID", "t1"."lastUpdated" FROM "movies" AS t1 WHERE ("t1"."statusID" = ?) [4]
>>> for movie in database.Movies.select().where(database.Movies.filename != None):
...   print movie.path
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2483, in __iter__
    return iter(self.execute())
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2476, in execute
    self._qr = ResultWrapper(model_class, self._execute(), query_meta)
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2172, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2788, in execute_sql
    self.commit()
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2657, in __exit__
    reraise(new_type, new_type(*exc_value.args), traceback)
  File "/share/CACHEDEV1_DATA/.qpkg/Python/lib/python2.7/site-packages/peewee.py", line 2780, in execute_sql
    cursor.execute(sql, params or ())
peewee.OperationalError: near "?": syntax error

The workaround i've done locally is to always save the filename in the database as the string "None". It's not particularly nice but it does workaround this specific issue. I'm also assuming that i'd never have a file which has the exact filename "None" :) This does mean that I use the default of "None" inside insert_movie so that when a Movie is initially created, it has been set.

I'm not sure if you'd like to include this workaround, but I thought best to document it here so that anyone else who has similar issues can see how to resolve it.

JasonMillward commented 9 years ago

That's certainly interesting, and thanks for doing all the research. It looks like you spent some time on it.

Since you've already got a fix I'd be happy to accept a pull request, or I'll update it myself in a day or two.

IanDBird commented 9 years ago

Great, i'll try and submit a PR very soon. There are a number of other things preventing me from running end to end testing on this particular setup, so am hoping to get that working before I push the changes. I also have a few other additions that I was going to push separately for discussion.