eniklas / gamatrix

Inspect GOG DBs and report the games in common between them
Mozilla Public License 2.0
11 stars 3 forks source link

fix igdb release key retrieval #117

Closed eniklas closed 1 year ago

eniklas commented 1 year ago

A few weeks ago, new GOG DBs started crashing the server when it processed them:

Feb 11 12:49:41 ebcc765a97b0[1812]: 2023-02-11 12:49:41 ERROR __main__ Exception on /compare [GET]
Feb 11 12:49:41 ebcc765a97b0[1812]: Traceback (most recent call last):
Feb 11 12:49:41 ebcc765a97b0[1812]:   File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2525, in wsgi_app
Feb 11 12:49:41 ebcc765a97b0[1812]:     response = self.full_dispatch_request()
Feb 11 12:49:41 ebcc765a97b0[1812]:                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 11 12:49:41 ebcc765a97b0[1812]:   File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1822, in full_dispatch_request
Feb 11 12:49:41 ebcc765a97b0[1812]:     rv = self.handle_user_exception(e)
Feb 11 12:49:41 ebcc765a97b0[1812]:          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 11 12:49:41 ebcc765a97b0[1812]:   File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1820, in full_dispatch_request
Feb 11 12:49:41 ebcc765a97b0[1812]:     rv = self.dispatch_request()
Feb 11 12:49:41 ebcc765a97b0[1812]:          ^^^^^^^^^^^^^^^^^^^^^^^
Feb 11 12:49:41 ebcc765a97b0[1812]:   File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1796, in dispatch_request
Feb 11 12:49:41 ebcc765a97b0[1812]:     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
Feb 11 12:49:41 ebcc765a97b0[1812]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 11 12:49:41 ebcc765a97b0[1812]:   File "/usr/local/lib/python3.11/site-packages/gamatrix/__main__.py", line 164, in compare_libraries
Feb 11 12:49:41 ebcc765a97b0[1812]:     common_games = gog.get_common_games()
Feb 11 12:49:41 ebcc765a97b0[1812]:                    ^^^^^^^^^^^^^^^^^^^^^^
Feb 11 12:49:41 ebcc765a97b0[1812]:   File "/usr/local/lib/python3.11/site-packages/gamatrix/helpers/gogdb_helper.py", line 239, in get_common_games
Feb 11 12:49:41 ebcc765a97b0[1812]:     ] = self.get_igdb_release_key(
Feb 11 12:49:41 ebcc765a97b0[1812]:         ^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 11 12:49:41 ebcc765a97b0[1812]:   File "/usr/local/lib/python3.11/site-packages/gamatrix/helpers/gogdb_helper.py", line 137, in get_igdb_release_key
Feb 11 12:49:41 ebcc765a97b0[1812]:     result = json.loads(self.cursor.fetchall()[0][-1])
Feb 11 12:49:41 ebcc765a97b0[1812]:              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 11 12:49:41 ebcc765a97b0[1812]:   File "/usr/local/lib/python3.11/json/__init__.py", line 339, in loads
Feb 11 12:49:41 ebcc765a97b0[1812]:     raise TypeError(f'the JSON object must be str, bytes or bytearray, '
Feb 11 12:49:41 ebcc765a97b0[1812]: TypeError: the JSON object must be str, bytes or bytearray, not NoneType

The schema in question is:

CREATE TABLE IF NOT EXISTS "GamePieces"(
    'releaseKey' TEXT NOT NULL,
    'gamePieceTypeId' INTEGER NOT NULL,
    'userId' INT64,
    'value' TEXT NOT NULL,
    'languageId' INTEGER NULL,
    CONSTRAINT 'FK_GamePieces_releaseKey_ReleaseKeys_key'
        FOREIGN KEY ('releaseKey')
        REFERENCES 'ReleaseKeys' ('key') ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT 'FK_GamePieces_gamePieceTypeId_GamePieceTypes_id'
        FOREIGN KEY ('gamePieceTypeId')
        REFERENCES 'GamePieceTypes' ('id') ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT 'FK_GamePieces_userId_Users_id'
        FOREIGN KEY ('userId')
        REFERENCES 'Users' ('id') ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT 'FK_GamePieces_languageId_Languages_id'
        FOREIGN KEY ('languageId')
        REFERENCES 'Languages' ('id') ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT 'UK_GamePieces_releaseKey_gamePieceTypeId_userId_languageId'
        UNIQUE ('releaseKey', 'gamePieceTypeId', 'userId', 'languageId'),
    CONSTRAINT 'CK_GamePieces_value'
        CHECK(trim([value]) <> ''),
    CONSTRAINT `CK_GamePieces_userId`
        CHECK([userId] > 0 OR [userId] IS NULL)
);

I haven't found release notes about this, but it seems that languageId was recently added. Gamatrix was assuming that the JSON blob it wanted (value) was the last item in the tuple. This updates it to assume it's the fourth item, which fixes the issue.