metaspace2020 / metaspace

Cloud engine and platform for metabolite annotation for imaging mass spectrometry
https://metaspace2020.eu/
Apache License 2.0
48 stars 10 forks source link

Remove fallback for string-based databases #721

Open LachlanStuart opened 3 years ago

LachlanStuart commented 3 years ago

It has actually been broken in the allAnnotations query for quite a while. This code attempts to unpack an array as though it were an object, and always fails to map the database name to an ID. There are occasional errors in Sentry, but nobody seems to have complained.

Additionally:

LachlanStuart commented 2 years ago

This is the error I mentioned:

message=Cannot destructure property 'name' of 'databaseNameVersionMapping[database]' as it is undefined., stack=TypeError: Cannot destructure property 'name' of 'databaseNameVersionMapping[database]' as it is undefined.
    at Object.exports.mapDatabaseToDatabaseId (/opt/dev/metaspace/metaspace/graphql/src/modules/moldb/util/mapDatabaseToDatabaseId.ts:27:13)
    at /opt/dev/metaspace/metaspace/graphql/src/modules/dataset/controller/Mutation.ts:225:64
    at Array.map (<anonymous>)
    at setDatabaseIdsInInput (/opt/dev/metaspace/metaspace/graphql/src/modules/dataset/controller/Mutation.ts:225:34)
    at createDataset (/opt/dev/metaspace/metaspace/graphql/src/modules/dataset/controller/Mutation.ts:248:9)
    at createDataset (/opt/dev/metaspace/metaspace/graphql/src/modules/dataset/controller/Mutation.ts:296:18)
    at field.resolve (/opt/dev/metaspace/metaspace/graphql/src/modules/system/addReadOnlyInterceptorToSchema.ts:29:34)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at /opt/dev/metaspace/metaspace/graphql/src/modules/system/addApiKeyInterceptorToSchema.ts:41:26
2021-01-18 10:56:38,841 - error: Cannot destructure property 'name' of 'databaseNameVersionMapping[database]' as it is undefined. Source {
  body: '\n' +
    '    mutation ($input: DatasetCreateInput!) {\n' +
    '      createDataset(input: $input)\n' +
    '    }\n' +
    '    ',
  name: 'GraphQL request',
  locationOffset: { line: 1, column: 1 }
}

Last occurrence was January 2021 - I think that it only happens with old versions of python-client. This codepath is only called if database is specified as a string instead of as an integer ID.

The problem is here:

const { name, version } = databaseNameVersionMapping[database];

Intended behavior can be fixed with this change ({ -> [):

const [ name, version ] = databaseNameVersionMapping[database];

however it would be better to just remove this whole codepath because it was only intended for backwards compatibility with old python-client, and clearly nobody uses those versions anymore.