Merge pull request #31577 from dwandro/master
fix(catalog-backend-incremental-ingestion): correctly handle count queries return strings
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend-module-incremental-ingestion': patch
|
||||
---
|
||||
|
||||
Correctly handle entity removal computation when DB count query returns string
|
||||
+45
@@ -17,6 +17,7 @@
|
||||
import { TestDatabases } from '@backstage/backend-test-utils';
|
||||
import { IncrementalIngestionDatabaseManager } from './IncrementalIngestionDatabaseManager';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { DeferredEntity } from '@backstage/plugin-catalog-node';
|
||||
|
||||
const migrationsDir = `${__dirname}/../../migrations`;
|
||||
|
||||
@@ -76,4 +77,48 @@ describe('IncrementalIngestionDatabaseManager', () => {
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(databases.eachSupportedId())(
|
||||
'computeRemoved correctly sums total count from count query, %p',
|
||||
async databaseId => {
|
||||
const knex = await databases.init(databaseId);
|
||||
await knex.migrate.latest({ directory: migrationsDir });
|
||||
|
||||
const manager = new IncrementalIngestionDatabaseManager({ client: knex });
|
||||
const { ingestionId } = (await manager.createProviderIngestionRecord(
|
||||
'testProvider',
|
||||
))!;
|
||||
|
||||
const markId = uuid();
|
||||
await manager.createMark({
|
||||
record: {
|
||||
id: markId,
|
||||
ingestion_id: ingestionId,
|
||||
sequence: 1,
|
||||
cursor: { data: 1 },
|
||||
},
|
||||
});
|
||||
|
||||
const makeEntity = (name: string): DeferredEntity => ({
|
||||
entity: {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: { namespace: 'default', name },
|
||||
},
|
||||
});
|
||||
|
||||
// Create multiple mark entities
|
||||
await manager.createMarkEntities(markId, [
|
||||
makeEntity('comp1'),
|
||||
makeEntity('comp2'),
|
||||
makeEntity('comp3'),
|
||||
]);
|
||||
|
||||
const result = await manager.computeRemoved('testProvider', ingestionId);
|
||||
|
||||
// On PostgreSQL, count queries return strings, so total should be 3 not NaN or string concatenation
|
||||
expect(result.total).toBe(3);
|
||||
expect(typeof result.total).toBe('number');
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
+1
-1
@@ -322,7 +322,7 @@ export class IncrementalIngestionDatabaseManager {
|
||||
.join('ingestions', 'ingestions.id', 'ingestion_marks.ingestion_id')
|
||||
.where('ingestions.id', ingestionId);
|
||||
|
||||
const total = count.reduce((acc, cur) => acc + (cur.total as number), 0);
|
||||
const total = count.reduce((acc, cur) => acc + Number(cur.total), 0);
|
||||
|
||||
const removed: { entityRef: string }[] = [];
|
||||
if (previousIngestion) {
|
||||
|
||||
Reference in New Issue
Block a user