morpheus65535 / bazarr

Bazarr is a companion application to Sonarr and Radarr. It manages and downloads subtitles based on your requirements. You define your preferences by TV show or movie and Bazarr takes care of everything for you.
https://www.bazarr.media
GNU General Public License v3.0
2.87k stars 223 forks source link

UNIQUE constraint failed: table_movies.path #1605

Closed ajkis closed 2 years ago

ajkis commented 3 years ago

Software (please complete the following informatio): Bazarr Version 1.0.0 Sonarr Version 3.0.6.1342 Radarr Version 3.2.2.5080 Operating System Linux-4.4.0-138-generic-x86_64-with-Ubuntu-16.04-xenial Python Version 3.7.10 Bazarr Directory /opt/bazarr Bazarr Config Directory /opt/bazarr/data

ERROR |apscheduler.executors.default |Job "update_movies (trigger: date[2021-11-06 16:39:04 CET], next run at: 2021-11-06 16:39:04 CET)" raised an exception|'Traceback (most recent call last):\n File "/opt/bazarr/bazarr/../libs/peewee.py", line 3144, in execute_sql\n cursor.execute(sql, params or ())\nsqlite3.IntegrityError: UNIQUE constraint failed: table_movies.path\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/opt/bazarr/bazarr/../libs/apscheduler/executors/base.py", line 125, in run_job\n retval = job.func(*job.args, **job.kwargs)\n File "/opt/bazarr/bazarr/get_movies.py", line 133, in update_movies\n TableMovies.update(updated_movie).where(TableMovies.tmdbId == updated_movie[\'tmdbId\']).execute()\n File "/opt/bazarr/bazarr/../libs/peewee.py", line 1907, in inner\n return method(self, database, *args, **kwargs)\n File "/opt/bazarr/bazarr/../libs/peewee.py", line 1978, in execute\n return self._execute(database)\n File "/opt/bazarr/bazarr/../libs/peewee.py", line 2475, in _execute\n return self.handle_result(database, cursor)\n File "/opt/bazarr/bazarr/../libs/peewee.py", line 2486, in handle_result\n return database.rows_affected(cursor)\n File "/opt/bazarr/bazarr/../libs/peewee.py", line 3236, in rows_affected\n return cursor.rowcount\n File "/opt/bazarr/bazarr/../libs/playhouse/sqliteq.py", line 94, in rowcount\n self._wait()\n File "/opt/bazarr/bazarr/../libs/playhouse/sqliteq.py", line 63, in _wait\n raise self._exc\n File "/opt/bazarr/bazarr/../libs/playhouse/sqliteq.py", line 178, in execute\n cursor = self.database._execute(obj.sql, obj.params, obj.commit)\n File "/opt/bazarr/bazarr/../libs/peewee.py", line 3151, in execute_sql\n self.commit()\n File "/opt/bazarr/bazarr/../libs/peewee.py", line 2917, in __exit__\n reraise(new_type, new_type(exc_value, *exc_args), traceback)\n File "/opt/bazarr/bazarr/../libs/peewee.py", line 190, in reraise\n raise value.with_traceback(tb)\n File "/opt/bazarr/bazarr/../libs/peewee.py", line 3144, in execute_sql\n cursor.execute(sql, params or ())\npeewee.IntegrityError: UNIQUE constraint failed: table_movies.path'|

morpheus65535 commented 3 years ago

You've reinstalled Radarr?

ajkis commented 3 years ago

No I updated it to v3 before i started to use bazarr

ajkis commented 3 years ago

Is there anything I could do to fix the problem. Both my Radarr and Sonarr were upgraded from v2 before I started to use bazarr.

I have quite big library and i would be pain if i needed to reinstall Radarr from scratch. Library = Movies Items = 12970

Library = TV Shows Items = 54871

ajkis commented 3 years ago

Data in table movies, field path: https://gist.github.com/ajkis/6cccf077b3360d23c65fb9320ed1a06a

Maybe some of the special chars in folder names are the cause of error.

morpheus65535 commented 3 years ago

The problem is that Radarr seems to have 2 times the same movie file index. I'm not sure how that's possible but Bazarr can't deal with it. The full debug log should show the problematic path. You can use a sqlite editor to remove the existing path from bazarr database (table_movies) and force a sync with radarr.

ajkis commented 3 years ago

This is from debug log. Anyway to figure out what record is duplicate table_movies.json https://easyupload.io/h8z6xn

ERROR   |apscheduler.executors.default   |Job "update_movies (trigger: date[2021-11-07 15:09:11 CET], next run at: 2021-11-07 15:09:11 CET)" raised an exception|Traceback (most recent call last):  File "/opt/bazarr/bazarr/../libs/peewee.py", line 3144, in execute_sql    cursor.execute(sql, params or ())sqlite3.IntegrityError: UNIQUE constraint failed: table_movies.pathDuring handling of the above exception, another exception occurred:Traceback (most recent call last):  File "/opt/bazarr/bazarr/../libs/apscheduler/executors/base.py", line 125, in run_job    retval = job.func(*job.args, **job.kwargs)  File "/opt/bazarr/bazarr/get_movies.py", line 133, in update_movies    TableMovies.update(updated_movie).where(TableMovies.tmdbId == updated_movie['tmdbId']).execute()  File "/opt/bazarr/bazarr/../libs/peewee.py", line 1907, in inner    return method(self, database, *args, **kwargs)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 1978, in execute    return self._execute(database)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 2475, in _execute    return self.handle_result(database, cursor)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 2486, in handle_result    return database.rows_affected(cursor)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 3236, in rows_affected    return cursor.rowcount  File "/opt/bazarr/bazarr/../libs/playhouse/sqliteq.py", line 94, in rowcount    self._wait()  File "/opt/bazarr/bazarr/../libs/playhouse/sqliteq.py", line 63, in _wait    raise self._exc  File "/opt/bazarr/bazarr/../libs/playhouse/sqliteq.py", line 178, in execute    cursor = self.database._execute(obj.sql, obj.params, obj.commit)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 3151, in execute_sql    self.commit()  File "/opt/bazarr/bazarr/../libs/peewee.py", line 2917, in __exit__    reraise(new_type, new_type(exc_value, *exc_args), traceback)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 190, in reraise    raise value.with_traceback(tb)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 3144, in execute_sql    cursor.execute(sql, params or ())peewee.IntegrityError: UNIQUE constraint failed: table_movies.path|

`ERROR   |apscheduler.executors.default   |Job "update_movies (trigger: date[2021-11-07 15:09:11 CET], next run at: 2021-11-07 15:09:11 CET)" raised an exception|Traceback (most recent call last):  File "/opt/bazarr/bazarr/../libs/peewee.py", line 3144, in execute_sql    cursor.execute(sql, params or ())sqlite3.IntegrityError: UNIQUE constraint failed: table_movies.pathDuring handling of the above exception, another exception occurred:Traceback (most recent call last):  File "/opt/bazarr/bazarr/../libs/apscheduler/executors/base.py", line 125, in run_job    retval = job.func(*job.args, **job.kwargs)  File "/opt/bazarr/bazarr/get_movies.py", line 133, in update_movies    TableMovies.update(updated_movie).where(TableMovies.tmdbId == updated_movie['tmdbId']).execute()  File "/opt/bazarr/bazarr/../libs/peewee.py", line 1907, in inner    return method(self, database, *args, **kwargs)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 1978, in execute    return self._execute(database)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 2475, in _execute    return self.handle_result(database, cursor)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 2486, in handle_result    return database.rows_affected(cursor)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 3236, in rows_affected    return cursor.rowcount  File "/opt/bazarr/bazarr/../libs/playhouse/sqliteq.py", line 94, in rowcount    self._wait()  File "/opt/bazarr/bazarr/../libs/playhouse/sqliteq.py", line 63, in _wait    raise self._exc  File "/opt/bazarr/bazarr/../libs/playhouse/sqliteq.py", line 178, in execute    cursor = self.database._execute(obj.sql, obj.params, obj.commit)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 3151, in execute_sql    self.commit()  File "/opt/bazarr/bazarr/../libs/peewee.py", line 2917, in __exit__    reraise(new_type, new_type(exc_value, *exc_args), traceback)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 190, in reraise    raise value.with_traceback(tb)  File "/opt/bazarr/bazarr/../libs/peewee.py", line 3144, in execute_sql    cursor.execute(sql, params or ())peewee.IntegrityError: UNIQUE constraint failed: table_movies.path|
`

p.s. When i originally installed bazarr to test it I had same error then I reinstalled it from scratch on plex server and there was same error.

morpheus65535 commented 3 years ago

I don't see the prematic path in your partial log. If you don't want to share your log, we'll stop there because there's not much I can do. If you want to send it in private on Discord, it's fine.

ajkis commented 3 years ago

Sorry for delay. Log file: https://easyupload.io/fgu6ao

morpheus65535 commented 3 years ago

Seems to be "/mnt/cloud/movies/Daddy's Girl (2020)/Daddy's Girl (2018) - Bluray-1080p.mkv". Check if you have two times this movies in Radarr. If not, open bazarr.db with an SQlite editor and remove from table_movies the row with that value in path: DELETE FROM tables_movies WHERE path = "/mnt/cloud/movies/Daddy's Girl (2020)/Daddy's Girl (2018) - Bluray-1080p.mkv"

ajkis commented 3 years ago

I deleted record Daddy Girl (2018) and Daddy Girl (2020) including files. When i rum radarr sync I receive same error. ( I truncated logs before running sync) Log https://easyupload.io/868huq

morpheus65535 commented 3 years ago

We can do it one by one but I would take a backup of the database, drop the content of table_movies and restart Bazarr. Let it run for a while during the indexation process. Sounds good?

ajkis commented 3 years ago

Will do it this weekend and let you know.

morpheus65535 commented 2 years ago

Have you been able to test it?

morpheus65535 commented 2 years ago

No news, good news.

cardeye commented 4 months ago

Had same issue, leaving a comment here for future persons with same issue

_sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint failed: tablemovies.path

The cause of the error in my case was that Radarr (5.7.0.8882) had had the same Movie folder path for the two movies, Stalker, from 2023

Stalker 2023 (tmdb 1103511) /Movies-09/Stalker (2023)/Stalker (2023) {tmdb-1004130} [WEBDL-720p] [H264] [AAC 2.0]-BAE.mkv

Stalker 2023 (tmdb 1004130) /Movies-09/Stalker (2023)/Stalker (2023) {tmdb-1004130} [WEBDL-720p] [H264] [AAC 2.0]-BAE.mkv

Due to the naming standard both movies was in same folder, but they appeared as two Movies in Radarr, and that crashed Bazarr

Solution was to manually rename one of the Movies movie folder in Radarr

And that showed up as a log entry in Radarr every time Bazarr crashed during the sync, as i tried to request Movie 0 (zero) Getting data for downloading item: api.Get(v3/movie/0): invalid status code, 404 >= 300, {