fix(catalog-backend-incremental-ingestion): correctly handle count queries returning strings
Signed-off-by: Dakota Wandro <dakotawan@gmail.com>
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
|
||||
+36
@@ -76,4 +76,40 @@ 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 },
|
||||
},
|
||||
});
|
||||
|
||||
// Create multiple mark entities
|
||||
await manager.createMarkEntities(markId, [
|
||||
{ entity: { kind: 'Component', namespace: 'default', name: 'comp1' } },
|
||||
{ entity: { kind: 'Component', namespace: 'default', name: 'comp2' } },
|
||||
{ entity: { kind: 'Component', namespace: 'default', name: '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