🐛 Fix saving credentials id as string (#2410)

This commit is contained in:
Ben Hesseldieck 2021-11-05 03:23:10 +01:00 committed by GitHub
parent e84846dcf9
commit a46c7f827d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View file

@ -39,7 +39,7 @@ export class UpdateWorkflowCredentials1630330987096 implements MigrationInterfac
// @ts-ignore // @ts-ignore
(credentials) => credentials.name === name && credentials.type === type, (credentials) => credentials.name === name && credentials.type === type,
); );
node.credentials[type] = { id: matchingCredentials?.id || null, name }; node.credentials[type] = { id: matchingCredentials?.id.toString() || null, name };
credentialsUpdated = true; credentialsUpdated = true;
} }
} }
@ -82,7 +82,7 @@ export class UpdateWorkflowCredentials1630330987096 implements MigrationInterfac
// @ts-ignore // @ts-ignore
(credentials) => credentials.name === name && credentials.type === type, (credentials) => credentials.name === name && credentials.type === type,
); );
node.credentials[type] = { id: matchingCredentials?.id || null, name }; node.credentials[type] = { id: matchingCredentials?.id.toString() || null, name };
credentialsUpdated = true; credentialsUpdated = true;
} }
} }
@ -126,7 +126,7 @@ export class UpdateWorkflowCredentials1630330987096 implements MigrationInterfac
// @ts-ignore // @ts-ignore
(credentials) => credentials.name === name && credentials.type === type, (credentials) => credentials.name === name && credentials.type === type,
); );
node.credentials[type] = { id: matchingCredentials?.id || null, name }; node.credentials[type] = { id: matchingCredentials?.id.toString() || null, name };
credentialsUpdated = true; credentialsUpdated = true;
} }
} }
@ -176,8 +176,8 @@ export class UpdateWorkflowCredentials1630330987096 implements MigrationInterfac
for (const [type, creds] of allNodeCredentials) { for (const [type, creds] of allNodeCredentials) {
if (typeof creds === 'object') { if (typeof creds === 'object') {
const matchingCredentials = credentialsEntities.find( const matchingCredentials = credentialsEntities.find(
// @ts-ignore // @ts-ignore double-equals because creds.id can be string or number
(credentials) => credentials.id === creds.id && credentials.type === type, (credentials) => credentials.id == creds.id && credentials.type === type,
); );
if (matchingCredentials) { if (matchingCredentials) {
node.credentials[type] = matchingCredentials.name; node.credentials[type] = matchingCredentials.name;
@ -226,8 +226,8 @@ export class UpdateWorkflowCredentials1630330987096 implements MigrationInterfac
for (const [type, creds] of allNodeCredentials) { for (const [type, creds] of allNodeCredentials) {
if (typeof creds === 'object') { if (typeof creds === 'object') {
const matchingCredentials = credentialsEntities.find( const matchingCredentials = credentialsEntities.find(
// @ts-ignore // @ts-ignore double-equals because creds.id can be string or number
(credentials) => credentials.id === creds.id && credentials.type === type, (credentials) => credentials.id == creds.id && credentials.type === type,
); );
if (matchingCredentials) { if (matchingCredentials) {
node.credentials[type] = matchingCredentials.name; node.credentials[type] = matchingCredentials.name;
@ -276,8 +276,8 @@ export class UpdateWorkflowCredentials1630330987096 implements MigrationInterfac
for (const [type, creds] of allNodeCredentials) { for (const [type, creds] of allNodeCredentials) {
if (typeof creds === 'object') { if (typeof creds === 'object') {
const matchingCredentials = credentialsEntities.find( const matchingCredentials = credentialsEntities.find(
// @ts-ignore // @ts-ignore double-equals because creds.id can be string or number
(credentials) => credentials.id === creds.id && credentials.type === type, (credentials) => credentials.id == creds.id && credentials.type === type,
); );
if (matchingCredentials) { if (matchingCredentials) {
node.credentials[type] = matchingCredentials.name; node.credentials[type] = matchingCredentials.name;

View file

@ -1917,10 +1917,13 @@ export default mixins(
if (nodeCredentials.id) { if (nodeCredentials.id) {
// Check whether the id is matching with a credential // Check whether the id is matching with a credential
const credentialsForId = credentialOptions.find((optionData: ICredentialsResponse) => optionData.id === nodeCredentials.id); const credentialsId = nodeCredentials.id.toString(); // due to a fixed bug in the migration UpdateWorkflowCredentials (just sqlite) we have to cast to string and check later if it has been a number
const credentialsForId = credentialOptions.find((optionData: ICredentialsResponse) =>
optionData.id === credentialsId,
);
if (credentialsForId) { if (credentialsForId) {
if (credentialsForId.name !== nodeCredentials.name) { if (credentialsForId.name !== nodeCredentials.name || typeof nodeCredentials.id === 'number') {
node.credentials![nodeCredentialType].name = credentialsForId.name; node.credentials![nodeCredentialType] = { id: credentialsForId.id, name: credentialsForId.name };
this.credentialsUpdated = true; this.credentialsUpdated = true;
} }
return; return;