CastagnaIT / plugin.video.netflix

InputStream based Netflix plugin for Kodi
MIT License
1.91k stars 259 forks source link

sqlite3 error during startup #1544

Closed paul20230815 closed 1 year ago

paul20230815 commented 1 year ago

Netflix add-on version

v1.20.4+matrix.1

Operative systems used

Linux (Ubuntu / Mint / ...)

Kodi version used

Kodi 19 (Matrix)

Description of the bug

During startup of Kodi or after fresh install of plugin.video.netflix I see the following message in the log:

2023-01-23 10:10:58.435 T:32537    INFO <general>: CAddonMgr::FindAddon: plugin.video.netflix v1.20.4+matrix.1 installed
2023-01-23 10:10:58.439 T:1037     INFO <general>: initializing python engine.
2023-01-23 10:10:58.571 T:14224 WARNING <general>: CGUIMediaWindow::OnMessage - updating in progress
2023-01-23 10:10:58.814 T:1037     INFO <general>: [plugin.video.netflix (0)] The debug logging is set as DISABLED
2023-01-23 10:10:58.991 T:1037    ERROR <general>: [plugin.video.netflix (0)] SQLite error Incorrect number of bindings supplied. The current statement uses 2, and there are 4 supplied.:
2023-01-23 10:10:58.991 T:1037    ERROR <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                                    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                                   Error Type: <class 'resources.lib.common.exceptions.DBSQLiteError'>
                                                   Traceback (most recent call last):
                                                     File "/home/hifi/.kodi/addons/plugin.video.netflix/resources/lib/database/db_base_sqlite.py", line 124, in _execute_non_query
                                                       cursor.execute(query, params)
                                                   sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 2, and there are 4 supplied.

                                                   The above exception was the direct cause of the following exception:

                                                   Traceback (most recent call last):
                                                     File "/home/hifi/.kodi/addons/plugin.video.netflix/service.py", line 13, in <module>
                                                       run(sys.argv)
                                                     File "/home/hifi/.kodi/addons/plugin.video.netflix/resources/lib/run_service.py", line 115, in run
                                                       G.init_globals(argv)
                                                     File "/home/hifi/.kodi/addons/plugin.video.netflix/resources/lib/globals.py", line 272, in init_globals
                                                       self.CACHE_MANAGEMENT = CacheManagement()
                                                     File "/home/hifi/.kodi/addons/plugin.video.netflix/resources/lib/services/cache_management.py", line 74, in __init__
                                                       self.next_schedule = _compute_next_schedule()
                                                     File "/home/hifi/.kodi/addons/plugin.video.netflix/resources/lib/services/cache_management.py", line 371, in _compute_next_schedule
                                                       G.LOCAL_DB.set_value('clean_cache_last_start', last_run)
                                                     File "/home/hifi/.kodi/addons/plugin.video.netflix/resources/lib/database/db_base_sqlite.py", line 53, in wrapper
                                                       return func(*args, **kwargs)
                                                     File "/home/hifi/.kodi/addons/plugin.video.netflix/resources/lib/database/db_base_sqlite.py", line 226, in set_value
                                                       self._execute_non_query(query, (key, value, value, key))
                                                     File "/home/hifi/.kodi/addons/plugin.video.netflix/resources/lib/database/db_base_sqlite.py", line 129, in _execute_non_query
                                                       raise DBSQLiteError from exc
                                                   resources.lib.common.exceptions.DBSQLiteError
                                                   -->End of Python script error report<--

2023-01-23 10:10:59.267 T:1037     INFO <general>: Python interpreter stopped

Same happens for version v1.20.5+matrix.1, version v1.20.3+matrix.1 still works fine. This is probably due to commit 2ac70df96aea1119743937a1ed07afb6de9f4698. I'm using libsqlite3-0:amd64 3.22.0-1ubuntu0.7. A bit debugging showed that params has indeed 4 items (log is gone unfortunately :-( ) I recall "1.20v5, service_previous_version, service_previous_version, 1.20v5" or similar.

Steps to reproduce the behavior

  1. Start Kodi v19 -matrix
  2. Install plugin.video.netflix v.20.4+matrix.1 or higher
  3. Kodi will display an error notification to check log file
  4. kodi.log contains attached message

Debug log - mandatory

https://paste.kodi.tv/tawaxivili.kodi

Possible fix

No response

Additional context

No response

Screenshots

No response

herrnst commented 1 year ago

Stumbled over this issue after updating plugin.video.netflix from 1.20.3 to 1.20.5 on an Ubuntu 18.04+Kodi Matrix 19.5 install, which has SQLite3 v3.22.

Reverting https://github.com/CastagnaIT/plugin.video.netflix/commit/2ac70df96aea1119743937a1ed07afb6de9f4698 "fixes" this.

CastagnaIT commented 1 year ago

please try replace the method code with this and let me know

    @handle_connection
    def set_value(self, key, value, table=db_utils.TABLE_APP_CONF):
        """
        Store a single value to database
        :param key: The key to store the value
        :param value: Value to save
        :param table: Table map
        """
        table_name = table[0]
        table_columns = table[1]
        value = common.convert_to_string(value)
        # Update or insert approach, if there is no updated row then insert new one (no id changes)
        if common.CmpVersion(sql.sqlite_version) < '3.24.0':
            query = f'INSERT OR REPLACE INTO {table_name} ({table_columns[0]}, {table_columns[1]}) VALUES (?, ?)'
            self._execute_non_query(query, (key, value))
        else:
            # sqlite UPSERT clause exists only on sqlite >= 3.24.0
            query = (f'INSERT INTO {table_name} ({table_columns[0]}, {table_columns[1]}) VALUES (?, ?) '
                     f'ON CONFLICT({table_columns[0]}) DO UPDATE SET {table_columns[1]} = ? '
                     f'WHERE {table_columns[0]} = ?')
            self._execute_non_query(query, (key, value, value, key))

seem that dont like have arguments to not be used

herrnst commented 1 year ago

Just tried with your replacement set_value(), which results in this diff:

--- a/resources/lib/database/db_base_sqlite.py
+++ b/resources/lib/database/db_base_sqlite.py
@@ -214,16 +214,17 @@ class SQLiteDatabase(db_base.BaseDatabase):
         """
         table_name = table[0]
         table_columns = table[1]
+        value = common.convert_to_string(value)
         # Update or insert approach, if there is no updated row then insert new one (no id changes)
         if common.CmpVersion(sql.sqlite_version) < '3.24.0':
             query = f'INSERT OR REPLACE INTO {table_name} ({table_columns[0]}, {table_columns[1]}) VALUES (?, ?)'
+            self._execute_non_query(query, (key, value))
         else:
             # sqlite UPSERT clause exists only on sqlite >= 3.24.0
             query = (f'INSERT INTO {table_name} ({table_columns[0]}, {table_columns[1]}) VALUES (?, ?) '
                      f'ON CONFLICT({table_columns[0]}) DO UPDATE SET {table_columns[1]} = ? '
                      f'WHERE {table_columns[0]} = ?')
-        value = common.convert_to_string(value)
-        self._execute_non_query(query, (key, value, value, key))
+            self._execute_non_query(query, (key, value, value, key))

     @handle_connection
     def set_values(self, dict_values, table=db_utils.TABLE_APP_CONF):

and everything works, ie. with unchanged master, plugin.video.netflix complains that background services are not started and cannot be started when opening the addon, with the diff applied it just starts as expected.

CastagnaIT commented 1 year ago

thanks for the feedback i will apply the changes

andreasdimo commented 1 year ago

What can we do to fix the problem?

CastagnaIT commented 1 year ago

its already fixed on new release

andreasdimo commented 1 year ago

And with the new version the problem remains. I am using the flatpak version of kodi

CastagnaIT commented 1 year ago

@andreasdimo open a new issue by fullfill bug template