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.76k stars 216 forks source link

Postgres error: "operator does not exist: text = integer" #2585

Closed bassterror closed 1 month ago

bassterror commented 1 month ago

Recently, I created a new instance of Bazarr with Postgres which in general is running ok, but the log is flooded with this error, which causes sync issues with Radarr and Sonarr. I did run the select statement through pgAdmin and indeed the WHERE clause needs an explicit cast. The weird thing is that this error is showing "randomly" and for different items. The example below is for the movie "Beverly Hills Cop: Axel F" and it was missing from Bazarr for a day or two (I didn't trace it), but then it finally synced and now it's in Bazarr.

error:

Traceback (most recent call last):
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/engine/base.py", line 1960, in _exec_single_context
    self.dialect.do_execute(
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/engine/default.py", line 924, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.UndefinedFunction: operator does not exist: text = integer
LINE 3: WHERE table_movies."tmdbId" = 280180
                                    ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/app/bazarr/bin/bazarr/../libs/apscheduler/executors/base.py", line 125, in run_job
    retval = job.func(*job.args, **job.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bazarr/bin/bazarr/radarr/sync/movies.py", line 166, in update_movies
    if get_movie_monitored_status(movie[\'tmdbId\']) != movie[\'monitored\']:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bazarr/bin/bazarr/radarr/sync/movies.py", line 60, in get_movie_monitored_status
    existing_movie_monitored = database.execute(
                               ^^^^^^^^^^^^^^^^^
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/orm/scoping.py", line 778, in execute
    return self._proxied.execute(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/orm/session.py", line 2306, in execute
    return self._execute_internal(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/orm/session.py", line 2191, in _execute_internal
    result: Result[Any] = compile_state_cls.orm_execute_statement(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/orm/context.py", line 293, in orm_execute_statement
    result = conn.execute(
             ^^^^^^^^^^^^^
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/engine/base.py", line 1408, in execute
    return meth(
           ^^^^^
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/sql/elements.py", line 513, in _execute_on_connection
    return connection._execute_clauseelement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/engine/base.py", line 1630, in _execute_clauseelement
    ret = self._execute_context(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/engine/base.py", line 1839, in _execute_context
    return self._exec_single_context(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/engine/base.py", line 1979, in _exec_single_context
    self._handle_dbapi_exception(
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/engine/base.py", line 2335, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/engine/base.py", line 1960, in _exec_single_context
    self.dialect.do_execute(
  File "/app/bazarr/bin/bazarr/../libs/sqlalchemy/engine/default.py", line 924, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedFunction) operator does not exist: text = integer
LINE 3: WHERE table_movies."tmdbId" = 280180
                                    ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
[SQL: SELECT table_movies.monitored 
FROM table_movies 
WHERE table_movies."tmdbId" = %(tmdbId_1)s]
[parameters: {\'tmdbId_1\': 280180}]
(Background on this error at: https://sqlalche.me/e/20/f405)

Software (please complete the following information):

Additional context bazarr:

services:
  bazarr:
    image: lscr.io/linuxserver/bazarr:latest
    container_name: bazarr
    restart: unless-stopped
    networks:
      - proxy
    volumes:
      - ./appdata:/config
      - ./appdata/scripts:/scripts
      - /volume1/Plex:/Plex
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=Europe/Sofia
      - DOCKER_MODS=ghcr.io/themepark-dev/theme.park:bazarr
      - TP_THEME=plex
      - POSTGRES_ENABLED=true
      - POSTGRES_HOST=${DB_HOST}
      - POSTGRES_PORT=${DB_PORT}
      - POSTGRES_DATABASE=${DB_DATABASE}
      - POSTGRES_USERNAME=${DB_USERNAME}
      - POSTGRES_PASSWORD=${DB_PASSWORD}

postgres:

services:
  postgres:
    restart: unless-stopped
    image: postgres:15
    container_name: postgres
    networks:
      - proxy
    volumes:
      - ./appdata/postgres:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
anderson-oki commented 1 month ago

May i ask if you have the same issue on Postgres 14? (Im sorry i havent really investigated yet, but just to narrow down the possibilities).

bassterror commented 1 month ago

I'm sorry for the late response! I don't have a Postgres 14 instance, but I'll try to test that very soon.

bassterror commented 1 month ago

I just tested it. It seems that is working correctly with Postgres 14. It successfully synced and every movie is present and analyzed in Bazarr.

Edit: Also, I see that the error in question, actually is thrown only for movies. All shows from Sonarr are successfully synced.

anderson-oki commented 1 month ago

Not related to the version, tmdbid is a text should probably be an int or the argument needs to be casted.

anderson-oki commented 1 month ago

It will be fixed on the upcoming beta.